]> granicus.if.org Git - clang/commitdiff
fix PR6782, an accept invalid. We weren't emitting the diagnostic
authorChris Lattner <sabre@nondot.org>
Mon, 5 Apr 2010 18:18:31 +0000 (18:18 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 5 Apr 2010 18:18:31 +0000 (18:18 +0000)
returned by SetTypeSpecType.

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

include/clang/Parse/Parser.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseStmt.cpp
test/Parser/cxx-decl.cpp

index 411162b18209ff5a9fda68ee313d4009415482ae..9a4634a420852171510a37edd48ae76e7bd64bf8 100644 (file)
@@ -1086,7 +1086,8 @@ private:
                                   CXX0XAttributeList Attr);
   DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context,
                                         SourceLocation &DeclEnd,
-                                        AttributeList *Attr);
+                                        AttributeList *Attr,
+                                        bool RequireSemi);
   DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
                                 bool AllowFunctionDefinitions,
                                 SourceLocation *DeclEnd = 0);
index e87d052141cc8c2975b75d594e29f4f2a6b01ab0..c85b6ee9746cd24b96870a6ced244902171a89ae 100644 (file)
@@ -334,7 +334,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclaration(unsigned Context,
     SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
     break;
   default:
-    return ParseSimpleDeclaration(Context, DeclEnd, Attr.AttrList);
+    return ParseSimpleDeclaration(Context, DeclEnd, Attr.AttrList, true);
   }
   
   // This routine returns a DeclGroup, if the thing we parsed only contains a
@@ -348,10 +348,11 @@ Parser::DeclGroupPtrTy Parser::ParseDeclaration(unsigned Context,
 /// [OMP]   threadprivate-directive                              [TODO]
 ///
 /// If RequireSemi is false, this does not check for a ';' at the end of the
-/// declaration.
+/// declaration.  If it is true, it checks for and eats it.
 Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context,
                                                       SourceLocation &DeclEnd,
-                                                      AttributeList *Attr) {
+                                                      AttributeList *Attr,
+                                                      bool RequireSemi) {
   // Parse the common declaration-specifiers piece.
   ParsingDeclSpec DS(*this);
   if (Attr)
@@ -362,15 +363,13 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context,
   // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
   // declaration-specifiers init-declarator-list[opt] ';'
   if (Tok.is(tok::semi)) {
-    ConsumeToken();
+    if (RequireSemi) ConsumeToken();
     DeclPtrTy TheDecl = Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
     DS.complete(TheDecl);
     return Actions.ConvertDeclToDeclGroup(TheDecl);
   }
 
-  DeclGroupPtrTy DG = ParseDeclGroup(DS, Context, /*FunctionDefs=*/ false,
-                                     &DeclEnd);
-  return DG;
+  return ParseDeclGroup(DS, Context, /*FunctionDefs=*/ false, &DeclEnd);
 }
 
 /// ParseDeclGroup - Having concluded that this is either a function
@@ -999,6 +998,10 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
                                        DiagID, Tok.getAnnotationValue());
       else
         DS.SetTypeSpecError();
+      
+      if (isInvalid)
+        break;
+
       DS.SetRangeEnd(Tok.getAnnotationEndLoc());
       ConsumeToken(); // The typename
 
index b752b48cfd49fc0a410d6fb433db5aaa64114a5e..b208c50c81bcb0868995853ada58834506388a99 100644 (file)
@@ -997,7 +997,7 @@ Parser::OwningStmtResult Parser::ParseForStatement(AttributeList *Attr) {
 
     SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
     DeclGroupPtrTy DG = ParseSimpleDeclaration(Declarator::ForContext, DeclEnd,
-                                               AttrList);
+                                               AttrList, false);
     FirstPart = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
 
     if (Tok.is(tok::semi)) {  // for (int x = 4;
index c8f2c0b7690398878f825210029c7a4a8a226898..ae004ce81c1d5347075d7b405ca247ec00626129 100644 (file)
@@ -62,3 +62,13 @@ struct test4 {
 // PR5825
 struct test5 {};
 ::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}}
+
+
+// PR6782
+template<class T>
+class Class1;
+
+class Class2 {
+}  // no ;
+
+typedef Class1<Class2> Type1; // expected-error {{cannot combine with previous 'class' declaration specifier}}