]> granicus.if.org Git - clang/commit
[coroutines] Build fallthrough and set_exception statements.
authorEric Fiselier <eric@efcs.ca>
Thu, 27 Oct 2016 07:30:31 +0000 (07:30 +0000)
committerEric Fiselier <eric@efcs.ca>
Thu, 27 Oct 2016 07:30:31 +0000 (07:30 +0000)
commit0834a353d3d8b3c730d0073ed3b1d6ad92402f2b
tree02032a17a0de632f2a8a3e7e7bd7b43949a76311
parentf1626ac6b7bd8e6164adc97988935a1364d2497f
[coroutines] Build fallthrough and set_exception statements.

Summary:
This patch adds semantic checking and building of the fall-through `co_return;` statement as well as the `p.set_exception(std::current_exception())` call for handling uncaught exceptions.

The fall-through statement is built and checked according to:
> [dcl.fct.def.coroutine]/4
> The unqualified-ids return_void and return_value are looked up in the scope of class P. If
> both are found, the program is ill-formed. If the unqualified-id 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.

Similarly the `set_exception` call is only built when that unqualified-id is found in the scope of class P.

Additionally this patch adds fall-through warnings for non-void returning coroutines. Since it's surprising undefined behavior I thought it would be important to add the warning right away.

Reviewers: majnemer, GorNishanov, rsmith

Subscribers: mehdi_amini, cfe-commits

Differential Revision: https://reviews.llvm.org/D25349

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285271 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/AST/StmtCXX.h
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/AnalysisBasedWarnings.cpp
lib/Sema/SemaCoroutine.cpp
lib/Sema/TreeTransform.h
test/SemaCXX/coreturn.cpp [new file with mode: 0644]
test/SemaCXX/coroutines.cpp