[cfe-commits] r67687 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp

Douglas Gregor dgregor at apple.com
Wed Mar 25 08:59:48 PDT 2009


Author: dgregor
Date: Wed Mar 25 10:59:44 2009
New Revision: 67687

URL: http://llvm.org/viewvc/llvm-project?rev=67687&view=rev
Log:
Predicate to detect when a RecordDecl is really the injected-class-name

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=67687&r1=67686&r2=67687&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Mar 25 10:59:44 2009
@@ -1113,6 +1113,21 @@
     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

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=67687&r1=67686&r2=67687&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Mar 25 10:59:44 2009
@@ -491,6 +491,11 @@
   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) {

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=67687&r1=67686&r2=67687&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 25 10:59:44 2009
@@ -3398,6 +3398,8 @@
                                 Record->getIdentifier(), Record);
       InjectedClassName->setImplicit();
       PushOnScopeChains(InjectedClassName, S);
+      assert(InjectedClassName->isInjectedClassName() && 
+             "Broken injected-class-name");
     }
   }
 }





More information about the cfe-commits mailing list