[C++20] [Coroutines] Allow promise_type to not define return_void or return_value
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Fri, 24 Dec 2021 05:33:52 +0000 (13:33 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Fri, 24 Dec 2021 05:37:51 +0000 (13:37 +0800)
commit097208dbf07786f3da84aec5b5f571c6e95a10e2
tree6212e535197043189c03155bc9b922677d7ab9c2
parent02478a26f269b6c212c4eb8b5e86d9fc641e9531
[C++20] [Coroutines] Allow promise_type to not define return_void or return_value

According to [dcl.fct.def.coroutine]p6, the promise_type is allowed to
not define return_void nor return_value:

> If searches for the names return_­void and return_­value in the scope
> of the promise type each find any declarations, the program is
> ill-formed.
> [Note 1: If return_­void is found, flowing off the end of a coroutine is
> equivalent to a co_­return with no operand. Otherwise, flowing off the
> end of a coroutine results in
> undefined behavior ([stmt.return.coroutine]). — end note]

So the program isn't ill-formed if the promise_type doesn't define
return_void nor return_value. It is just a potential UB. So the program
should be allowed to compile.

Reviewed By: urnathan

Differential Revision: https://reviews.llvm.org/D116204
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaCoroutine.cpp
clang/test/SemaCXX/coroutines-exp-namespace.cpp
clang/test/SemaCXX/coroutines.cpp