public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-10641] c++: co_await and initializer_list [PR103871]
Date: Sat, 22 Apr 2023 00:22:41 +0000 (GMT)	[thread overview]
Message-ID: <20230422002241.BA71B3857705@sourceware.org> (raw)

https://gcc.gnu.org/g:998e77e55126269b3e67b2f05f0f27a421839673

commit r11-10641-g998e77e55126269b3e67b2f05f0f27a421839673
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 15 16:33:37 2023 -0400

    c++: co_await and initializer_list [PR103871]
    
    When flatten_await_stmt processes the backing array for an initializer_list,
    we call cp_build_modify_expr to initialize the promoted variable from the
    TARGET_EXPR; that needs to be accepted.
    
            PR c++/103871
            PR c++/98056
    
    gcc/cp/ChangeLog:
    
            * typeck.c (cp_build_modify_expr): Allow array initialization of
            DECL_ARTIFICIAL variable.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/coroutines/co-await-initlist1.C: New test.

Diff:
---
 gcc/cp/typeck.c                                     |  2 ++
 .../g++.dg/coroutines/co-await-initlist1.C          | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index e61d67727f0..c2b703e3cf0 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8891,6 +8891,8 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
 	}
 
       /* Allow array assignment in compiler-generated code.  */
+      else if (DECL_P (lhs) && DECL_ARTIFICIAL (lhs))
+	/* OK, used by coroutines (co-await-initlist1.C).  */;
       else if (!current_function_decl
 	       || !DECL_DEFAULTED_FN (current_function_decl))
 	{
diff --git a/gcc/testsuite/g++.dg/coroutines/co-await-initlist1.C b/gcc/testsuite/g++.dg/coroutines/co-await-initlist1.C
new file mode 100644
index 00000000000..b8e8923a9c8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/co-await-initlist1.C
@@ -0,0 +1,21 @@
+// PR c++/103871
+// { dg-do compile { target c++20 } }
+
+#include <coroutine>
+#include <initializer_list>
+
+struct my_coro {
+  struct promise_type {
+    my_coro get_return_object();
+    std::suspend_never initial_suspend();
+    std::suspend_never final_suspend() noexcept;
+    void unhandled_exception();
+  };
+};
+
+std::suspend_never inner(std::initializer_list<int>);
+
+my_coro doesnt_work()
+{
+  co_await inner({ 1,2,3 });
+}

                 reply	other threads:[~2023-04-22  0:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230422002241.BA71B3857705@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).