[cfe-commits] r55652 - /cfe/trunk/lib/Sema/SemaDecl.cpp
Ted Kremenek
kremenek at apple.com
Tue Sep 2 14:26:19 PDT 2008
Author: kremenek
Date: Tue Sep 2 16:26:19 2008
New Revision: 55652
URL: http://llvm.org/viewvc/llvm-project?rev=55652&view=rev
Log:
When creating CXXRecordDecls and RecordDecls within ActOnTag, hook up the new [CXX]RecordDecl with the RecordDecl chain.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=55652&r1=55651&r2=55652&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 2 16:26:19 2008
@@ -1683,9 +1683,10 @@
// 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<ScopedDecl>(LookupDecl(Name, Decl::IDNS_Tag, S))) {
-
+ ScopedDecl *PrevDecl =
+ dyn_cast_or_null<ScopedDecl>(LookupDecl(Name, Decl::IDNS_Tag, S));
+
+ if (PrevDecl) {
assert((isa<TagDecl>(PrevDecl) || isa<NamespaceDecl>(PrevDecl)) &&
"unexpected Decl type");
if (TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) {
@@ -1758,9 +1759,18 @@
// 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<CXXRecordDecl>(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<RecordDecl>(PrevDecl));
}
// If this has an identifier, add it to the scope stack.
More information about the cfe-commits
mailing list