diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 01b018857a7fc..edb05ca54caf0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -295,6 +295,8 @@ Bug Fixes to C++ Support direct-list-initialized from an array is corrected to direct-initialization. - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327) - Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386) +- Clang will emit an error instead of crash when use co_await or co_yield in + C++26 braced-init-list template parameter initialization. (#GH78426) - Fixes matching of nested template template parameters. (#GH130362) - Correctly diagnoses template template paramters which have a pack parameter not in the last position. diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index 0e4f3b20c78cd..53536b0d14037 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -788,7 +788,11 @@ static bool checkSuspensionContext(Sema &S, SourceLocation Loc, // First emphasis of [expr.await]p2: must be a potentially evaluated context. // That is, 'co_await' and 'co_yield' cannot appear in subexpressions of // \c sizeof. - if (S.isUnevaluatedContext()) { + const auto ExprContext = S.currentEvaluationContext().ExprContext; + const bool BadContext = + S.isUnevaluatedContext() || + ExprContext != Sema::ExpressionEvaluationContextRecord::EK_Other; + if (BadContext) { S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword; return false; } @@ -798,7 +802,6 @@ static bool checkSuspensionContext(Sema &S, SourceLocation Loc, S.Diag(Loc, diag::err_coroutine_within_handler) << Keyword; return false; } - return true; } diff --git a/clang/test/SemaCXX/coroutine-decltype.cpp b/clang/test/SemaCXX/coroutine-unevaluate.cpp similarity index 78% rename from clang/test/SemaCXX/coroutine-decltype.cpp rename to clang/test/SemaCXX/coroutine-unevaluate.cpp index 7cbe6688d4155..164caed2836a1 100644 --- a/clang/test/SemaCXX/coroutine-decltype.cpp +++ b/clang/test/SemaCXX/coroutine-unevaluate.cpp @@ -32,3 +32,11 @@ MyTask DoAnotherthing() { static_assert(__is_same(void, decltype(co_yield 0))); // expected-error {{'co_yield' cannot be used in an unevaluated context}} co_return; } + +template +struct Task {}; + +void BracedInitListCXX26() { + []() -> Task<{ co_await 1 }> {}; // expected-error {{'co_await' cannot be used in an unevaluated context}} + []() -> Task<{ co_yield 1 }> {}; // expected-error {{'co_yield' cannot be used in an unevaluated context}} +}