diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-03-25 15:59:44 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-03-25 15:59:44 +0000 |
commit | c9b5b4074bd73d4af76e69cccf8ecd365fdd1008 (patch) | |
tree | a03432759ff18983fe948f9deb9a0e6c3c896b10 | |
parent | 4f722be4587a7a0dece399fb5405dda158971ae1 (diff) |
Predicate to detect when a RecordDecl is really the injected-class-name
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67687 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Decl.h | 15 | ||||
-rw-r--r-- | lib/AST/Decl.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 2 |
3 files changed, 22 insertions, 0 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 34b863512b..f811ffa75a 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -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 diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 321ccf34f9..15a20bd050 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -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) { diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index b76126aa8f..fd89507645 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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"); } } } |