[cfe-commits] r150817 - /cfe/trunk/lib/Parse/ParseInit.cpp

Douglas Gregor dgregor at apple.com
Fri Feb 17 08:41:17 PST 2012


Author: dgregor
Date: Fri Feb 17 10:41:16 2012
New Revision: 150817

URL: http://llvm.org/viewvc/llvm-project?rev=150817&view=rev
Log:
De-nest tentative parsing to disambiguate lambdas from designators; no
functionality change.

Modified:
    cfe/trunk/lib/Parse/ParseInit.cpp

Modified: cfe/trunk/lib/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=150817&r1=150816&r2=150817&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Fri Feb 17 10:41:16 2012
@@ -58,52 +58,55 @@
       return true;        
     }
     
-    // Parse up to (at most) the token after the closing ']' to determine 
-    // whether this is a C99 designator or a lambda.
-    TentativeParsingAction Tentative(*this);
-    ConsumeBracket();
-    while (true) {
-      switch (Tok.getKind()) {
-      case tok::equal:
-      case tok::amp:
-      case tok::identifier:
-      case tok::kw_this:
-        // These tokens can occur in a capture list or a constant-expression.
-        // Keep looking.
-        ConsumeToken();
-        continue;
-          
-      case tok::comma:
-        // Since a comma cannot occur in a constant-expression, this must
-        // be a lambda.
-        Tentative.Revert();
-        return false;
-          
-      case tok::r_square: {
-        // Once we hit the closing square bracket, we look at the next
-        // token. If it's an '=', this is a designator. Otherwise, it's a
-        // lambda expression. This decision favors lambdas over the older
-        // GNU designator syntax, which allows one to omit the '=', but is
-        // consistent with GCC.
-        ConsumeBracket();
-        tok::TokenKind Kind = Tok.getKind();
-        Tentative.Revert();
-        return Kind == tok::equal;
-      }
-          
-      default:
-        // Anything else cannot occur in a lambda capture list, so it
-        // must be a designator.
-        Tentative.Revert();
-        return true;
-      }
-    }
-    
-    return true;
+    // Handle the complicated case below.
+    break;    
   }
   case tok::identifier:  // designation: identifier ':'
     return PP.LookAhead(0).is(tok::colon);
   }
+  
+  // Parse up to (at most) the token after the closing ']' to determine 
+  // whether this is a C99 designator or a lambda.
+  TentativeParsingAction Tentative(*this);
+  ConsumeBracket();
+  while (true) {
+    switch (Tok.getKind()) {
+    case tok::equal:
+    case tok::amp:
+    case tok::identifier:
+    case tok::kw_this:
+      // These tokens can occur in a capture list or a constant-expression.
+      // Keep looking.
+      ConsumeToken();
+      continue;
+      
+    case tok::comma:
+      // Since a comma cannot occur in a constant-expression, this must
+      // be a lambda.
+      Tentative.Revert();
+      return false;
+      
+    case tok::r_square: {
+      // Once we hit the closing square bracket, we look at the next
+      // token. If it's an '=', this is a designator. Otherwise, it's a
+      // lambda expression. This decision favors lambdas over the older
+      // GNU designator syntax, which allows one to omit the '=', but is
+      // consistent with GCC.
+      ConsumeBracket();
+      tok::TokenKind Kind = Tok.getKind();
+      Tentative.Revert();
+      return Kind == tok::equal;
+    }
+      
+    default:
+      // Anything else cannot occur in a lambda capture list, so it
+      // must be a designator.
+      Tentative.Revert();
+      return true;
+    }
+  }
+  
+  return true;
 }
 
 static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc,





More information about the cfe-commits mailing list