]> granicus.if.org Git - clang/commitdiff
Predicate to detect when a RecordDecl is really the injected-class-name
authorDouglas Gregor <dgregor@apple.com>
Wed, 25 Mar 2009 15:59:44 +0000 (15:59 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 25 Mar 2009 15:59:44 +0000 (15:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67687 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp

index 34b863512b8beef3d66b593ce07232990306e64b..f811ffa75a0a54b6dd3182db2a8ab1bdf12e4e1e 100644 (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
index 321ccf34f965ce7e91b3b72fb82acf102a9991e3..15a20bd050cc440bb93cd1c23b392fe3653b0dac 100644 (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) {
index b76126aa8fcbd3552b548062290c54788d829c95..fd89507645ae6f3fcd98ae65edfcfcddff5b914e 100644 (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");
     }
   }
 }