]> granicus.if.org Git - clang/commitdiff
Parse: It's cleaner to handle cxx_defaultarg_end in SkipUntil directly
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 12 Jan 2015 03:36:37 +0000 (03:36 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 12 Jan 2015 03:36:37 +0000 (03:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225616 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseCXXInlineMethods.cpp
lib/Parse/ParseExprCXX.cpp
lib/Parse/Parser.cpp
test/Parser/cxx-member-initializers.cpp

index 7c9cceb12bcfd6eb4937e12266cd2c0ff27daebc..ccd051721fa9e7a3b213bfa5b2a621d78f528674 100644 (file)
@@ -652,6 +652,7 @@ bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
 
     switch (Tok.getKind()) {
     case tok::eof:
+    case tok::cxx_defaultarg_end:
     case tok::annot_module_begin:
     case tok::annot_module_end:
     case tok::annot_module_include:
index 68bd45e38d1ecdc59cba8299fd5988caa3249e87..355503caa9be678e64245536ff4798d9560ad947 100644 (file)
@@ -716,16 +716,9 @@ ExprResult Parser::ParseLambdaExpression() {
   Optional<unsigned> DiagID = ParseLambdaIntroducer(Intro);
   if (DiagID) {
     Diag(Tok, DiagID.getValue());
-    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);
+    SkipUntil(tok::r_square, StopAtSemi);
+    SkipUntil(tok::l_brace, StopAtSemi);
+    SkipUntil(tok::r_brace, StopAtSemi);
     return ExprError();
   }
 
index c9243d64880c239543ee68b0cae07a4ae13d6252..06a70f7fd33222d0e4c22a7910fa71fb0931549f 100644 (file)
@@ -262,6 +262,10 @@ bool Parser::SkipUntil(ArrayRef<tok::TokenKind> Toks, SkipUntilFlags Flags) {
       // Ran out of tokens.
       return false;
 
+    case tok::cxx_defaultarg_end:
+      // It's never desirable to consume the 'end-of-default-argument' token.
+      return false;
+
     case tok::annot_pragma_openmp_end:
       // Stop before an OpenMP pragma boundary.
     case tok::annot_module_begin:
@@ -1948,7 +1952,7 @@ bool BalancedDelimiterTracker::diagnoseMissingClose() {
   // token.
   if (P.Tok.isNot(tok::r_paren) && P.Tok.isNot(tok::r_brace) &&
       P.Tok.isNot(tok::r_square) &&
-      P.SkipUntil(Close, FinalToken, tok::cxx_defaultarg_end,
+      P.SkipUntil(Close, FinalToken,
                   Parser::StopAtSemi | Parser::StopBeforeMatch) &&
       P.Tok.is(Close))
     LClose = P.ConsumeAnyToken();
index 461810c62fbb8268a2ab77459a12a35deba7101c..ee509b115e99f120844ed1b9f3616802a76e3d80 100644 (file)
@@ -103,5 +103,5 @@ class G {
   void l(int x = C<int, C<int, int>::C1>().f()) {}
 
   // This isn't, but it shouldn't crash. The diagnostics don't matter much.
-  void m(int x = C<int, union int>().f()) {} // expected-error {{declaration of anonymous union must be a definition}}
-}; // expected-error {{expected a type}}
+  void m(int x = C<int, union int>().f()) {} // expected-error {{declaration of anonymous union must be a definition}} expected-error {{expected a type}}
+};