According https://eel.is/c++draft/expr.const#10.23 "an await-expression ([expr.await]);" await expression are not allowed in constant evaluation. GCC accepts it, but silently not evaluate it. ```c++ auto test() -> super_simple_coroutine { constexpr auto x = co_await awaitable{}; } ``` This code should be rejected. EDG and Clang rejects it, GCC silently accepts it but attempt to read value yields error about reading uninitialized value, MSVC does yeild similar error straight error about reading the error. I think GCC should reject this.
Dop you have a full example because the code snipit here definitely is rejected.
https://compiler-explorer.com/z/58reoonEW (trunk GCC 2ef2b206c4617abae60002280455f7175aaa6064) ```c++ #include <coroutine> struct awaitable { constexpr bool await_ready() { return true; } void await_suspend(std::coroutine_handle<void>) { } constexpr int await_resume() { return 42; } }; struct super_simple_coroutine { struct promise_type { constexpr auto initial_suspend() { return std::suspend_never(); } constexpr auto final_suspend() const noexcept { return std::suspend_never(); } constexpr void unhandled_exception() { // do nothing } constexpr auto get_return_object() { return super_simple_coroutine{}; } constexpr void return_void() { } }; }; auto fib() -> super_simple_coroutine { // if `co_await` is part of BodyStatement of a function // it makes it coroutine constexpr auto x = co_await awaitable{}; } ```
Confirmed. Yes looks like GCC ignores constexpr with co_await.
testing a patch
posted actually co_await was being recognised as not suitable for constexpr; but I had omitted the diagnostic.
The master branch has been updated by Iain D Sandoe <iains@gcc.gnu.org>: https://gcc.gnu.org/g:0ae77a05c416c9f750cb87f1bef0800651168b7e commit r16-1059-g0ae77a05c416c9f750cb87f1bef0800651168b7e Author: Iain Sandoe <iain@sandoe.co.uk> Date: Fri May 30 20:09:40 2025 +0100 c++: Emit an error for attempted constexpr co_await [PR118903]. We checked that the coroutine expressions were not suitable for constexpr, but did not emit and error when needed. PR c++/118903 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1): Emit an error when co_await et. al. are used in constexpr contexts. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr118903.C: New test. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
The releases/gcc-15 branch has been updated by Iain D Sandoe <iains@gcc.gnu.org>: https://gcc.gnu.org/g:b9b3471a9eb3f490b74b57236b4c122045dbcf56 commit r15-10092-gb9b3471a9eb3f490b74b57236b4c122045dbcf56 Author: Iain Sandoe <iain@sandoe.co.uk> Date: Fri May 30 20:09:40 2025 +0100 c++: Emit an error for attempted constexpr co_await [PR118903]. We checked that the coroutine expressions were not suitable for constexpr, but did not emit and error when needed. PR c++/118903 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1): Emit an error when co_await et. al. are used in constexpr contexts. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr118903.C: New test. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk> (cherry picked from commit 0ae77a05c416c9f750cb87f1bef0800651168b7e)
fixed for 15.2