aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-17 00:42:38 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-17 00:42:38 +0000
commit0b7a158d120ac8d78c114a823e17eedfec6b6658 (patch)
tree06cb618c16a5c1e606f20e137a6be209ddb8bbe1 /lib/AST/DeclBase.cpp
parent41f2b32df5faff10c305ef1892fcb02846e4f489 (diff)
Teach DeclContext how to find the primary declaration for any TagDecl
even when we are still defining the TagDecl. This is required so that qualified name lookup of a class name within its definition works (see the new bits in test/SemaCXX/qualified-id-lookup.cpp). As part of this, move the nested redefinition checking code into ActOnTag. This gives us diagnostics earlier (when we try to perform the nested redefinition, rather than when we try to complete the 2nd definition) and removes some code duplication. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62386 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r--lib/AST/DeclBase.cpp36
1 files changed, 7 insertions, 29 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 860a65a1e3..28656873ab 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -442,37 +442,15 @@ DeclContext *DeclContext::getPrimaryContext() {
return static_cast<NamespaceDecl*>(this)->getOriginalNamespace();
case Decl::Enum:
-#if 0
- // FIXME: See the comment for CXXRecord, below.
- // The declaration associated with the enumeration type is our
- // primary context.
- return Context.getTypeDeclType(static_cast<EnumDecl*>(this))
- ->getAsEnumType()->getDecl();
-#else
- return this;
-#endif
-
case Decl::Record:
- case Decl::CXXRecord: {
- // The declaration associated with the type is be our primary
- // context.
-#if 0
- // FIXME: This is what we expect to do. However, it doesn't work
- // because ASTContext::setTagDefinition changes the result of
- // Context.getTypeDeclType, meaning that our "primary" declaration
- // of a RecordDecl/CXXRecordDecl will change, and we won't be able
- // to find any values inserted into the earlier "primary"
- // declaration. We need better tracking of redeclarations and
- // definitions.
- QualType Type = Context.getTypeDeclType(static_cast<RecordDecl*>(this));
- return Type->getAsRecordType()->getDecl();
-#else
- // FIXME: This hack will work for now, because the declaration we
- // create when we're defining the record is the one we'll use as
- // the definition later.
+ case Decl::CXXRecord:
+ // If this is a tag type that has a definition or is currently
+ // being defined, that definition is our primary context.
+ if (TagType *TagT = cast_or_null<TagType>(cast<TagDecl>(this)->TypeForDecl))
+ if (TagT->isBeingDefined() ||
+ (TagT->getDecl() && TagT->getDecl()->isDefinition()))
+ return TagT->getDecl();
return this;
-#endif
- }
case Decl::ObjCMethod:
return this;