From 7e8cc57bad2b670b0a3b48fa3d84dce79b5c7288 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 2 Sep 2008 21:26:19 +0000 Subject: [PATCH] When creating CXXRecordDecls and RecordDecls within ActOnTag, hook up the new [CXX]RecordDecl with the RecordDecl chain. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55652 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 564f530191..7c660bf595 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1683,9 +1683,10 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK, // If this is a named struct, check to see if there was a previous forward // declaration or definition. // Use ScopedDecl instead of TagDecl, because a NamespaceDecl may come up. - if (ScopedDecl *PrevDecl = - dyn_cast_or_null(LookupDecl(Name, Decl::IDNS_Tag, S))) { - + ScopedDecl *PrevDecl = + dyn_cast_or_null(LookupDecl(Name, Decl::IDNS_Tag, S)); + + if (PrevDecl) { assert((isa(PrevDecl) || isa(PrevDecl)) && "unexpected Decl type"); if (TagDecl *PrevTagDecl = dyn_cast(PrevDecl)) { @@ -1758,9 +1759,18 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK, // struct X { int A; } D; D should chain to X. if (getLangOptions().CPlusPlus) // FIXME: Look for a way to use RecordDecl for simple structs. - New = CXXRecordDecl::Create(Context, Kind, CurContext, Loc, Name, 0); + + // We use 'dyn_cast' instead of 'cast' because PrevDecl might not + // be a CXXRecordDecl* if we had a redefinition error. In this case, + // the dyn_cast will return a NULL pointer. + New = CXXRecordDecl::Create(Context, Kind, CurContext, Loc, Name, + dyn_cast_or_null(PrevDecl)); else - New = RecordDecl::Create(Context, Kind, CurContext, Loc, Name, 0); + // We use 'dyn_cast' instead of 'cast' because PrevDecl might not + // be a RecordDecl* if we had a redefinition error. In this case, + // the dyn_cast will return a NULL pointer. + New = RecordDecl::Create(Context, Kind, CurContext, Loc, Name, + dyn_cast_or_null(PrevDecl)); } // If this has an identifier, add it to the scope stack. -- 2.50.1