]> granicus.if.org Git - clang/commitdiff
fix incorrect parsing of bitfields pointed out by Doug. I chose
authorChris Lattner <sabre@nondot.org>
Thu, 10 Dec 2009 01:59:24 +0000 (01:59 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 10 Dec 2009 01:59:24 +0000 (01:59 +0000)
to use ColonProtectionRAIIObject in the C codepath even though it
won't matter for consistency.

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

lib/Parse/ParseDecl.cpp
lib/Parse/ParseDeclCXX.cpp
test/Parser/cxx-decl.cpp

index 5a657dea9b2443095cfe863e66e0ae6f836d6993..2a6a0494e57f9135f25ae6e1a228f219cc7ac91f 100644 (file)
@@ -1,4 +1,3 @@
-
 //===--- ParseDecl.cpp - Declaration Parsing ------------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
@@ -1545,8 +1544,11 @@ ParseStructDeclaration(DeclSpec &DS, FieldCallback &Fields) {
 
     /// struct-declarator: declarator
     /// struct-declarator: declarator[opt] ':' constant-expression
-    if (Tok.isNot(tok::colon))
+    if (Tok.isNot(tok::colon)) {
+      // Don't parse FOO:BAR as if it were a typo for FOO::BAR.
+      ColonProtectionRAIIObject X(*this);
       ParseDeclarator(DeclaratorInfo.D);
+    }
 
     if (Tok.is(tok::colon)) {
       ConsumeToken();
index d9c8d7da76fdc02e32a471b6892022a658bd9119..34ea9c7d9b025d6c51a5cf0cfd60499a6f1059cf 100644 (file)
@@ -1090,11 +1090,13 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
     return ParseCXXClassMemberDeclaration(AS, TemplateInfo);
   }
 
+  // Don't parse FOO:BAR as if it were a typo for FOO::BAR.
+  ColonProtectionRAIIObject X(*this);
+  
   CXX0XAttributeList AttrList;
   // Optional C++0x attribute-specifier
-  if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
+  if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
     AttrList = ParseCXX0XAttributes();
-  }
 
   if (Tok.is(tok::kw_using)) {
     // FIXME: Check for template aliases
@@ -1138,6 +1140,9 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext);
 
   if (Tok.isNot(tok::colon)) {
+    // Don't parse FOO:BAR as if it were a typo for FOO::BAR.
+    ColonProtectionRAIIObject X(*this);
+
     // Parse the first declarator.
     ParseDeclarator(DeclaratorInfo);
     // Error parsing the declarator?
index 308700e50d66607050a44b16c90dbaf1258065cb..4453c4c3d0d23187dc97d5eb0155c79cabafabb0 100644 (file)
@@ -2,6 +2,8 @@
 
 int x(*g); // expected-error {{use of undeclared identifier 'g'}}
 
+struct Type { };
+
 
 // PR4451 - We should recover well from the typo of '::' as ':' in a2.
 namespace y {
@@ -31,3 +33,10 @@ class someclass {
     return 1 ? P->x : P->y;
   }
 };
+
+enum { fooenum = 1 };
+
+struct a {
+  int Type : fooenum;
+};
+