summaryrefslogtreecommitdiffstats
path: root/lib/Parse
diff options
context:
space:
mode:
authorBrian Gesiak <modocache@gmail.com>2019-03-15 20:25:49 +0000
committerBrian Gesiak <modocache@gmail.com>2019-03-15 20:25:49 +0000
commitca894734be1f06683c941a0037e5739a74310637 (patch)
tree2285090632845c2c83c82732696b4f717ab24ffd /lib/Parse
parentfc62308da45f483cd97bcf823f5a01b025f6a8ba (diff)
[coroutines][PR40978] Emit error for co_yield within catch block
Summary: As reported in https://bugs.llvm.org/show_bug.cgi?id=40978, it's an error to use the `co_yield` or `co_await` keywords outside of a valid "suspension context" as defined by [expr.await]p2 of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/n4775.pdf. Whether or not the current scope was in a function-try-block's (https://en.cppreference.com/w/cpp/language/function-try-block) handler could be determined using scope flag `Scope::FnTryCatchScope`. No such flag existed for a simple C++ catch statement, so this commit adds one. Reviewers: GorNishanov, tks2103, rsmith Reviewed By: GorNishanov Subscribers: EricWF, jdoerfert, cfe-commits, lewissbaker Tags: #clang Differential Revision: https://reviews.llvm.org/D59076 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356296 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse')
-rw-r--r--lib/Parse/ParseStmt.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 267003b518..fde19b9ad8 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -2260,8 +2260,10 @@ StmtResult Parser::ParseCXXCatchBlock(bool FnCatch) {
// C++ 3.3.2p3:
// The name in a catch exception-declaration is local to the handler and
// shall not be redeclared in the outermost block of the handler.
- ParseScope CatchScope(this, Scope::DeclScope | Scope::ControlScope |
- (FnCatch ? Scope::FnTryCatchScope : 0));
+ unsigned ScopeFlags = Scope::DeclScope | Scope::ControlScope |
+ Scope::CatchScope |
+ (FnCatch ? Scope::FnTryCatchScope : 0);
+ ParseScope CatchScope(this, ScopeFlags);
// exception-declaration is equivalent to '...' or a parameter-declaration
// without default arguments.
@@ -2290,7 +2292,7 @@ StmtResult Parser::ParseCXXCatchBlock(bool FnCatch) {
return StmtError(Diag(Tok, diag::err_expected) << tok::l_brace);
// FIXME: Possible draft standard bug: attribute-specifier should be allowed?
- StmtResult Block(ParseCompoundStatement());
+ StmtResult Block(ParseCompoundStatement(/*isStmtExpr=*/false, ScopeFlags));
if (Block.isInvalid())
return Block;