From 2559629c5bf218bf74ab52c49e88bfe04e895a85 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 9 Mar 2012 20:10:30 +0000 Subject: Improve our semantic error recovery. When an error made a record member invalid, the record would stay as "isBeingDefined" and not "completeDefinition". Even easily recoverable errors ended up propagating records in such "beingDefined" state, for example: struct A { ~A() const; // expected-error {{'const' qualifier is not allowed on a destructor}} }; struct B : A {}; // A & B would stay as "not complete definition" and "being defined". This weird state was impending lookups in the records and hitting assertion in the ASTWriter. Part of rdar://11007039 llvm-svn: 152432 --- clang/lib/Sema/SemaDecl.cpp | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'clang/lib/Sema/SemaDecl.cpp') diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6c25a20e248..5febad616c2 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2378,8 +2378,11 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, Tag = CTD->getTemplatedDecl(); } - if (Tag) + if (Tag) { Tag->setFreeStanding(); + if (Tag->isInvalidDecl()) + return Tag; + } if (unsigned TypeQuals = DS.getTypeQualifiers()) { // Enforce C99 6.7.3p2: "Types other than pointer types derived from object @@ -8601,6 +8604,13 @@ void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD, TagDecl *Tag = cast(TagD); Tag->setRBraceLoc(RBraceLoc); + // Make sure we "complete" the definition even it is invalid. + if (Tag->isBeingDefined()) { + assert(Tag->isInvalidDecl() && "We should already have completed it"); + if (RecordDecl *RD = dyn_cast(Tag)) + RD->completeDefinition(); + } + if (isa(Tag)) FieldCollector->FinishClass(); @@ -8632,6 +8642,12 @@ void Sema::ActOnTagDefinitionError(Scope *S, Decl *TagD) { TagDecl *Tag = cast(TagD); Tag->setInvalidDecl(); + // Make sure we "complete" the definition even it is invalid. + if (Tag->isBeingDefined()) { + if (RecordDecl *RD = dyn_cast(Tag)) + RD->completeDefinition(); + } + // We're undoing ActOnTagStartDefinition here, not // ActOnStartCXXMemberDeclarations, so we don't have to mess with // the FieldCollector. @@ -8840,11 +8856,19 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T, } QualType EltTy = Context.getBaseElementType(T); - if (!EltTy->isDependentType() && - RequireCompleteType(Loc, EltTy, diag::err_field_incomplete)) { - // Fields of incomplete type force their record to be invalid. - Record->setInvalidDecl(); - InvalidDecl = true; + if (!EltTy->isDependentType()) { + if (RequireCompleteType(Loc, EltTy, diag::err_field_incomplete)) { + // Fields of incomplete type force their record to be invalid. + Record->setInvalidDecl(); + InvalidDecl = true; + } else { + NamedDecl *Def; + EltTy->isIncompleteType(&Def); + if (Def && Def->isInvalidDecl()) { + Record->setInvalidDecl(); + InvalidDecl = true; + } + } } // C99 6.7.2.1p8: A member of a structure or union may have any type other -- cgit v1.2.3