]> granicus.if.org Git - clang/commitdiff
Handle unnamed bitfields when parsing C++ classes.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 28 Jun 2008 08:10:48 +0000 (08:10 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 28 Jun 2008 08:10:48 +0000 (08:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52855 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDeclCXX.cpp
test/Parser/cxx-class.cpp

index 718cea9586408d90f51b18096f3e241a90c2d90f..c84b5e7de6e0a0b57a010f61538591c56a5f9ed8 100644 (file)
@@ -412,38 +412,41 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) {
     }
   }
   
-  // Parse the first declarator.
   Declarator DeclaratorInfo(DS, Declarator::MemberContext);
-  ParseDeclarator(DeclaratorInfo);
-  // Error parsing the declarator?
-  if (DeclaratorInfo.getIdentifier() == 0) {
-    // If so, skip until the semi-colon or a }.
-    SkipUntil(tok::r_brace, true);
-    if (Tok.is(tok::semi))
-      ConsumeToken();
-    return 0;
-  }
 
-  // function-definition:
-  if (Tok.is(tok::l_brace)) {
-    if (!DeclaratorInfo.isFunctionDeclarator()) {
-      Diag(Tok, diag::err_func_def_no_params);
-      ConsumeBrace();
+  if (Tok.isNot(tok::colon)) {
+    // Parse the first declarator.
+    ParseDeclarator(DeclaratorInfo);
+    // Error parsing the declarator?
+    if (DeclaratorInfo.getIdentifier() == 0) {
+      // If so, skip until the semi-colon or a }.
       SkipUntil(tok::r_brace, true);
+      if (Tok.is(tok::semi))
+        ConsumeToken();
       return 0;
     }
 
-    if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
-      Diag(Tok, diag::err_function_declared_typedef);
-      // This recovery skips the entire function body. It would be nice
-      // to simply call ParseCXXInlineMethodDef() below, however Sema
-      // assumes the declarator represents a function, not a typedef.
-      ConsumeBrace();
-      SkipUntil(tok::r_brace, true);
-      return 0;
-    }
+    // function-definition:
+    if (Tok.is(tok::l_brace)) {
+      if (!DeclaratorInfo.isFunctionDeclarator()) {
+        Diag(Tok, diag::err_func_def_no_params);
+        ConsumeBrace();
+        SkipUntil(tok::r_brace, true);
+        return 0;
+      }
+
+      if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
+        Diag(Tok, diag::err_function_declared_typedef);
+        // This recovery skips the entire function body. It would be nice
+        // to simply call ParseCXXInlineMethodDef() below, however Sema
+        // assumes the declarator represents a function, not a typedef.
+        ConsumeBrace();
+        SkipUntil(tok::r_brace, true);
+        return 0;
+      }
 
-    return ParseCXXInlineMethodDef(AS, DeclaratorInfo);
+      return ParseCXXInlineMethodDef(AS, DeclaratorInfo);
+    }
   }
 
   // member-declarator-list:
@@ -510,7 +513,8 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) {
     if (Tok.is(tok::kw___attribute))
       DeclaratorInfo.AddAttributes(ParseAttributes());
 
-    ParseDeclarator(DeclaratorInfo);
+    if (Tok.isNot(tok::colon))
+      ParseDeclarator(DeclaratorInfo);
   }
 
   if (Tok.is(tok::semi)) {
index f0b419d494eca8c0cf88d1b71b804d9abe9d9a64..6d030bdc578aa9a2416f80659c658721bcc34e55 100644 (file)
@@ -8,6 +8,7 @@ protected:
   struct S {};
   enum {};
   int; // expected-error {{error: declaration does not declare anything}}
+  int : 1, : 2;
 
 public:
   void m() {