OK for master? / backports? (when?)
thanks,
Iain
PR c++/103868
gcc/cp/ChangeLog:
* coroutines.cc (finish_co_await_expr): Do not process non-dependent
coroutine expressions at template definition time.
(finish_co_yield_expr): Likewise.
(finish_co_return_stmt): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/pr103868.C: New test.
Co-Authored-by: Iain Sandoe <i...@sandoe.co.uk>
---
gcc/cp/coroutines.cc | 18 +-
gcc/testsuite/g++.dg/coroutines/pr103868.C | 7390 ++++++++++++++++++++
2 files changed, 7396 insertions(+), 12 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/coroutines/pr103868.C
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index cdf6503c4d3..a9ce6e050dd 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1148,10 +1148,8 @@ finish_co_await_expr (location_t kw, tree expr)
extraneous warnings during substitution. */
suppress_warning (current_function_decl, OPT_Wreturn_type);
- /* If we don't know the promise type, we can't proceed, build the
- co_await with the expression unchanged. */
- tree functype = TREE_TYPE (current_function_decl);
- if (dependent_type_p (functype) || type_dependent_expression_p (expr))
+ /* Defer processing when we have dependent types. */
+ if (processing_template_decl)
{
tree aw_expr = build5_loc (kw, CO_AWAIT_EXPR, unknown_type_node, expr,
NULL_TREE, NULL_TREE, NULL_TREE,
@@ -1222,10 +1220,8 @@ finish_co_yield_expr (location_t kw, tree expr)
extraneous warnings during substitution. */
suppress_warning (current_function_decl, OPT_Wreturn_type);
- /* If we don't know the promise type, we can't proceed, build the
- co_await with the expression unchanged. */
- tree functype = TREE_TYPE (current_function_decl);
- if (dependent_type_p (functype) || type_dependent_expression_p (expr))
+ /* Defer processing when we have dependent types. */
+ if (processing_template_decl)
return build2_loc (kw, CO_YIELD_EXPR, unknown_type_node, expr, NULL_TREE);
if (!coro_promise_type_found_p (current_function_decl, kw))
@@ -1307,10 +1303,8 @@ finish_co_return_stmt (location_t kw, tree expr)
&& check_for_bare_parameter_packs (expr))
return error_mark_node;
- /* If we don't know the promise type, we can't proceed, build the
- co_return with the expression unchanged. */
- tree functype = TREE_TYPE (current_function_decl);
- if (dependent_type_p (functype) || type_dependent_expression_p (expr))
+ /* Defer processing when we have dependent types. */
+ if (processing_template_decl)
{
/* co_return expressions are always void type, regardless of the
expression type. */