Predicate to detect when a RecordDecl is really the injected-class-name

llvm-svn: 67687
This commit is contained in:
Douglas Gregor
2009-03-25 15:59:44 +00:00
parent 8a6555332f
commit dfcad11842
3 changed files with 22 additions and 0 deletions

View File

@@ -1113,6 +1113,21 @@ public:
AnonymousStructOrUnion = Anon;
}
/// \brief Determines whether this declaration represents the
/// injected class name.
///
/// The injected class name in C++ is the name of the class that
/// appears inside the class itself. For example:
///
/// \code
/// struct C {
/// // C is implicitly declared here as a synonym for the class name.
/// };
///
/// C::C c; // same as "C c;"
/// \endcode
bool isInjectedClassName() const;
/// getDefinition - Returns the RecordDecl that actually defines this
/// struct/union/class. When determining whether or not a struct/union/class
/// is completely defined, one should use this method as opposed to

View File

@@ -491,6 +491,11 @@ void RecordDecl::Destroy(ASTContext& C) {
TagDecl::Destroy(C);
}
bool RecordDecl::isInjectedClassName() const {
return isImplicit() && getDeclName() && getDeclContext()->isRecord() &&
cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName();
}
/// completeDefinition - Notes that the definition of this type is now
/// complete.
void RecordDecl::completeDefinition(ASTContext& C) {

View File

@@ -3398,6 +3398,8 @@ void Sema::ActOnTagStartDefinition(Scope *S, DeclTy *TagD) {
Record->getIdentifier(), Record);
InjectedClassName->setImplicit();
PushOnScopeChains(InjectedClassName, S);
assert(InjectedClassName->isInjectedClassName() &&
"Broken injected-class-name");
}
}
}