Clean up after ourselves when there's an error parsing the base clause.
Fixes the crash-on-invalid in PR6629.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98698 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index 11f84ed..9e232cb 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -1520,6 +1520,9 @@
 
     if (!Tok.is(tok::l_brace)) {
       Diag(Tok, diag::err_expected_lbrace_after_base_specifiers);
+
+      if (TagDecl)
+        Actions.ActOnTagDefinitionError(CurScope, TagDecl);
       return;
     }
   }
@@ -1596,11 +1599,11 @@
     ParseLexedMethodDefs(getCurrentClass());
   }
 
+  Actions.ActOnTagFinishDefinition(CurScope, TagDecl, RBraceLoc);
+
   // Leave the class scope.
   ParsingDef.Pop();
   ClassScope.Exit();
-
-  Actions.ActOnTagFinishDefinition(CurScope, TagDecl, RBraceLoc);
 }
 
 /// ParseConstructorInitializer - Parse a C++ constructor initializer,
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index a18d5f1..9251ab7 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -939,6 +939,10 @@
   virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl,
                                         SourceLocation RBraceLoc);
 
+  /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
+  /// error parsing the definition of a tag.
+  virtual void ActOnTagDefinitionError(Scope *S, DeclPtrTy TagDecl);
+
   EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
                                       EnumConstantDecl *LastEnumConst,
                                       SourceLocation IdLoc,
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 5db8171..f4b9cf4 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -5118,6 +5118,18 @@
   Consumer.HandleTagDeclDefinition(Tag);
 }
 
+void Sema::ActOnTagDefinitionError(Scope *S, DeclPtrTy TagD) {
+  AdjustDeclIfTemplate(TagD);
+  TagDecl *Tag = cast<TagDecl>(TagD.getAs<Decl>());
+
+  Tag->setInvalidDecl();
+
+  if (isa<CXXRecordDecl>(Tag))
+    FieldCollector->FinishClass();
+
+  PopDeclContext();  
+}
+
 // Note that FieldName may be null for anonymous bitfields.
 bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
                           QualType FieldTy, const Expr *BitWidth,