Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)

Bug Fixes to AST Handling
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Sema/SemaCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -798,7 +802,6 @@ static bool checkSuspensionContext(Sema &S, SourceLocation Loc,
S.Diag(Loc, diag::err_coroutine_within_handler) << Keyword;
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<class>
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}}
}