]> granicus.if.org Git - clang/commitdiff
If we enter parens, colons can become un-sacred, allowing us to emit
authorChris Lattner <sabre@nondot.org>
Thu, 10 Dec 2009 02:08:07 +0000 (02:08 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 10 Dec 2009 02:08:07 +0000 (02:08 +0000)
a better diagnostic in the second example.

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

lib/Parse/ParseExpr.cpp
lib/Parse/RAIIObjectsForParser.h
test/Parser/cxx-decl.cpp

index 2536cee1cbdbcee3e28e678630fea01704ac1701..bdbc67f782dcfd09c99984c1f037e3d4c028f6fc 100644 (file)
@@ -565,9 +565,15 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,
     TypeTy *CastTy;
     SourceLocation LParenLoc = Tok.getLocation();
     SourceLocation RParenLoc;
-    Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
-                               TypeOfCast, CastTy, RParenLoc);
-    if (Res.isInvalid()) return move(Res);
+    
+    {
+      // The inside of the parens don't need to be a colon protected scope.
+      ColonProtectionRAIIObject X(*this, false);
+    
+      Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
+                                 TypeOfCast, CastTy, RParenLoc);
+      if (Res.isInvalid()) return move(Res);
+    }
 
     switch (ParenExprType) {
     case SimpleExpr:   break;    // Nothing else to do.
index 93b9a82fdca86a4cfce1bc1c28a9e9f365605b74..d048f043413bc2e4df46d5a40a8e65d8aefd4e35 100644 (file)
@@ -48,8 +48,9 @@ namespace clang {
     Parser &P;
     bool OldVal;
   public:
-    ColonProtectionRAIIObject(Parser &p) : P(p), OldVal(P.ColonIsSacred) {
-      P.ColonIsSacred = true;
+    ColonProtectionRAIIObject(Parser &p, bool Value = true)
+      : P(p), OldVal(P.ColonIsSacred) {
+      P.ColonIsSacred = Value;
     }
     
     /// restore - This can be used to restore the state early, before the dtor
index 38467117b340bc31a7052fe97ab55945ccedc522..6f3fd391b95ac9a80fc2b95db7e60811ae8b295e 100644 (file)
@@ -9,7 +9,8 @@ struct Type {
 
 // PR4451 - We should recover well from the typo of '::' as ':' in a2.
 namespace y {
-  struct a { };  
+  struct a { };
+  typedef int b;
 }
 
 y::a a1;
@@ -45,4 +46,9 @@ struct a {
 void test(struct Type *P) {
   int Type;
   Type = 1 ? P->Type : Type;
+  
+  Type = (y:b) 4;   // expected-error {{unexpected ':' in nested name specifier}}
+  Type = 1 ? (
+              (y:b)  // expected-error {{unexpected ':' in nested name specifier}}
+              4) : 5;
 }
\ No newline at end of file