EricWF created this revision.
Herald added a subscriber: mehdi_amini.
A `co_await arg` expression has a dependent type whenever the promise type is
still dependent, even if the argument to co_await is not. This is because we
cannot attempt the `await_transform(<arg>)` until after we know the promise
type.
This patch fixes an assertion in the constructor of `DependentCoawaitExpr` that
asserted that `arg` must also be dependent.
https://reviews.llvm.org/D30772
Files:
include/clang/AST/ExprCXX.h
test/SemaCXX/coroutines.cpp
Index: test/SemaCXX/coroutines.cpp
===================================================================
--- test/SemaCXX/coroutines.cpp
+++ test/SemaCXX/coroutines.cpp
@@ -151,6 +151,12 @@
co_return 42;
}
+template <class T>
+void co_await_non_dependent_arg(T) {
+ co_await a;
+}
+template void co_await_non_dependent_arg(int);
+
void mixed_yield() {
co_yield 0; // expected-note {{use of 'co_yield'}}
return; // expected-error {{not allowed in coroutine}}
Index: include/clang/AST/ExprCXX.h
===================================================================
--- include/clang/AST/ExprCXX.h
+++ include/clang/AST/ExprCXX.h
@@ -4236,7 +4236,9 @@
/*InstantiationDependent*/ true,
Op->containsUnexpandedParameterPack()),
KeywordLoc(KeywordLoc) {
- assert(Op->isTypeDependent() && Ty->isDependentType() &&
+ // NOTE: A co_await expression is dependent on the coroutines promise
+ // type and may be dependent even when the `Op` expression is not.
+ assert(Ty->isDependentType() &&
"wrong constructor for non-dependent co_await/co_yield expression");
SubExprs[0] = Op;
SubExprs[1] = OpCoawait;
Index: test/SemaCXX/coroutines.cpp
===================================================================
--- test/SemaCXX/coroutines.cpp
+++ test/SemaCXX/coroutines.cpp
@@ -151,6 +151,12 @@
co_return 42;
}
+template <class T>
+void co_await_non_dependent_arg(T) {
+ co_await a;
+}
+template void co_await_non_dependent_arg(int);
+
void mixed_yield() {
co_yield 0; // expected-note {{use of 'co_yield'}}
return; // expected-error {{not allowed in coroutine}}
Index: include/clang/AST/ExprCXX.h
===================================================================
--- include/clang/AST/ExprCXX.h
+++ include/clang/AST/ExprCXX.h
@@ -4236,7 +4236,9 @@
/*InstantiationDependent*/ true,
Op->containsUnexpandedParameterPack()),
KeywordLoc(KeywordLoc) {
- assert(Op->isTypeDependent() && Ty->isDependentType() &&
+ // NOTE: A co_await expression is dependent on the coroutines promise
+ // type and may be dependent even when the `Op` expression is not.
+ assert(Ty->isDependentType() &&
"wrong constructor for non-dependent co_await/co_yield expression");
SubExprs[0] = Op;
SubExprs[1] = OpCoawait;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits