[gcc r13-6702] c++: co_await and initializer_list [PR103871]
Jason Merrill
jason@gcc.gnu.org
Wed Mar 15 22:29:48 GMT 2023
https://gcc.gnu.org/g:ea4dd8f512979db247c54d6b41377bb73699bcd7
commit r13-6702-gea4dd8f512979db247c54d6b41377bb73699bcd7
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.cc (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.cc | 2 ++
.../g++.dg/coroutines/co-await-initlist1.C | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index d5a3e501d8e..afb956087ce 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -9630,6 +9630,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 });
+}
More information about the Gcc-cvs
mailing list