diff options
author | Jan Korous <jkorous@apple.com> | 2017-11-06 17:42:17 +0000 |
---|---|---|
committer | Jan Korous <jkorous@apple.com> | 2017-11-06 17:42:17 +0000 |
commit | 0b7495e18087b0676af7e25a18f1434dc40b963b (patch) | |
tree | cb3bac2c8afaf560cf322953901caf3cc31a5079 | |
parent | 157a622d78eb0e71dcef8ec08ebed2d20ca1772f (diff) | |
download | clang-0b7495e18087b0676af7e25a18f1434dc40b963b.tar.gz |
[Parser] Fix TryParseLambdaIntroducer() error handling
rdar://35066196
Differential Revision: https://reviews.llvm.org/D39419
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317493 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 35 | ||||
-rw-r--r-- | test/Parser/objcxx11-invalid-lambda.cpp | 10 |
2 files changed, 31 insertions, 14 deletions
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index ce6aa64de6..ad4801971a 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -991,27 +991,34 @@ Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, /// /// Returns true if it hit something unexpected. bool Parser::TryParseLambdaIntroducer(LambdaIntroducer &Intro) { - TentativeParsingAction PA(*this); + { + bool SkippedInits = false; + TentativeParsingAction PA1(*this); - bool SkippedInits = false; - Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro, &SkippedInits)); + if (ParseLambdaIntroducer(Intro, &SkippedInits)) { + PA1.Revert(); + return true; + } - if (DiagID) { - PA.Revert(); - return true; + if (!SkippedInits) { + PA1.Commit(); + return false; + } + + PA1.Revert(); } - if (SkippedInits) { - // Parse it again, but this time parse the init-captures too. - PA.Revert(); - Intro = LambdaIntroducer(); - DiagID = ParseLambdaIntroducer(Intro); - assert(!DiagID && "parsing lambda-introducer failed on reparse"); + // Try to parse it again, but this time parse the init-captures too. + Intro = LambdaIntroducer(); + TentativeParsingAction PA2(*this); + + if (!ParseLambdaIntroducer(Intro)) { + PA2.Commit(); return false; } - PA.Commit(); - return false; + PA2.Revert(); + return true; } static void diff --git a/test/Parser/objcxx11-invalid-lambda.cpp b/test/Parser/objcxx11-invalid-lambda.cpp new file mode 100644 index 0000000000..74c5636b6a --- /dev/null +++ b/test/Parser/objcxx11-invalid-lambda.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -x objective-c++ -std=c++11 %s + +void foo() { // expected-note {{to match this '{'}} + int bar; + auto baz = [ + bar( // expected-note {{to match this '('}} expected-note {{to match this '('}} + foo_undeclared() // expected-error{{use of undeclared identifier 'foo_undeclared'}} expected-error{{use of undeclared identifier 'foo_undeclared'}} + /* ) */ + ] () { }; // expected-error{{expected ')'}} +} // expected-error{{expected ')'}} expected-error{{expected ';' at end of declaration}} expected-error{{expected '}'}} |