]> granicus.if.org Git - clang/commitdiff
Parse: Don't parse beyond the end of the synthetic default argument tok
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 12 Jan 2015 02:28:16 +0000 (02:28 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 12 Jan 2015 02:28:16 +0000 (02:28 +0000)
Recovery from malformed lambda introducers would find us consuming the
synthetic default argument token, which is bad.  Instead, stop right
before that token.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225613 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExprCXX.cpp
test/Parser/cxx0x-lambda-expressions.cpp

index 355503caa9be678e64245536ff4798d9560ad947..68bd45e38d1ecdc59cba8299fd5988caa3249e87 100644 (file)
@@ -716,9 +716,16 @@ ExprResult Parser::ParseLambdaExpression() {
   Optional<unsigned> DiagID = ParseLambdaIntroducer(Intro);
   if (DiagID) {
     Diag(Tok, DiagID.getValue());
-    SkipUntil(tok::r_square, StopAtSemi);
-    SkipUntil(tok::l_brace, StopAtSemi);
-    SkipUntil(tok::r_brace, StopAtSemi);
+    auto SkipUntilLambdaToken = [&](tok::TokenKind LambdaToken) {
+      // Don't skip past the end of the default argument.
+      SkipUntil(LambdaToken, tok::cxx_defaultarg_end,
+                StopAtSemi | StopBeforeMatch);
+      if (Tok.is(LambdaToken))
+        ConsumeAnyToken();
+    };
+    SkipUntilLambdaToken(tok::r_square);
+    SkipUntilLambdaToken(tok::l_brace);
+    SkipUntilLambdaToken(tok::r_brace);
     return ExprError();
   }
 
index 4bcc60c73c1df2b96c194ace11bfd7fba61f36ca..e1be75686ad0bf2eb19127861f471ad801fe138c 100644 (file)
@@ -98,3 +98,8 @@ void PR22122() {
 }
 
 template void PR22122<int>();
+
+struct S {
+  template <typename T>
+  void m (T x =[0); // expected-error{{expected variable name or 'this' in lambda capture list}}
+} s;