[cfe-commits] r72526 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h lib/AST/Decl.cpp lib/AST/DeclBase.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-declref.cpp

Douglas Gregor dgregor at apple.com
Thu May 28 09:34:51 PDT 2009


Author: dgregor
Date: Thu May 28 11:34:51 2009
New Revision: 72526

URL: http://llvm.org/viewvc/llvm-project?rev=72526&view=rev
Log:
Introduced DeclContext::isDependentContext, which determines whether a
given DeclContext is dependent on type parameters. Use this to
properly determine whether a TagDecl is dependent; previously, we were
missing the case where the TagDecl is a local class of a member
function of a class template (phew!).

Also, make sure that, when we instantiate declarations within a member
function of a class template (or a function template, eventually),
that we add those declarations to the "instantiated locals" map so
that they can be found when instantiating declaration references.

Unfortunately, I was not able to write a useful test for this change,
although the assert() that fires when uncommenting the FIXME'd line in
test/SemaTemplate/instantiate-declref.cpp tells the "experienced user"
that we're now doing the right thing.


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-declref.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu May 28 11:34:51 2009
@@ -1081,7 +1081,7 @@
   /// \brief Whether this declaration declares a type that is
   /// dependent, i.e., a type that somehow depends on template
   /// parameters.
-  bool isDependentType() const;
+  bool isDependentType() const { return isDependentContext(); }
 
   /// @brief Starts the definition of this tag declaration.
   /// 

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu May 28 11:34:51 2009
@@ -441,6 +441,10 @@
     return DeclKind == Decl::Namespace;
   }
 
+  /// \brief Determines whether this context is dependent on a
+  /// template parameter.
+  bool isDependentContext() const;
+
   /// isTransparentContext - Determines whether this context is a
   /// "transparent" context, meaning that the members declared in this
   /// context are semantically declared in the nearest enclosing

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

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu May 28 11:34:51 2009
@@ -528,19 +528,6 @@
 // TagDecl Implementation
 //===----------------------------------------------------------------------===//
 
-bool TagDecl::isDependentType() const {
-  if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this))
-    if (Record->getDescribedClassTemplate())
-      return true;
-    
-  if (const TagDecl *TD = dyn_cast_or_null<TagDecl>(getDeclContext()))
-    return TD->isDependentType();
-
-  // FIXME: Tag types declared function templates are dependent types.
-  // FIXME: Look through block scopes.
-  return false;
-}
-
 void TagDecl::startDefinition() {
   TagType *TagT = const_cast<TagType *>(TypeForDecl->getAsTagType());
   TagT->decl.setPointer(this);

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

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu May 28 11:34:51 2009
@@ -396,6 +396,21 @@
     (*D++)->Destroy(C);
 }
 
+bool DeclContext::isDependentContext() const {
+  if (isFileContext())
+    return false;
+
+  if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this))
+    if (Record->getDescribedClassTemplate())
+      return true;
+
+  if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(this))
+    if (Function->getDescribedFunctionTemplate())
+      return true;
+  
+  return getParent() && getParent()->isDependentContext();
+}
+
 bool DeclContext::isTransparentContext() const {
   if (DeclKind == Decl::Enum)
     return true; // FIXME: Check for C++0x scoped enums

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu May 28 11:34:51 2009
@@ -97,6 +97,9 @@
     Typedef->setInvalidDecl();
 
   Owner->addDecl(SemaRef.Context, Typedef);
+  if (Owner->isFunctionOrMethod())
+    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Typedef);
+    
   return Typedef;
 }
 
@@ -211,6 +214,8 @@
   Enum->setInstantiationOfMemberEnum(D);
   Enum->setAccess(D->getAccess());
   Owner->addDecl(SemaRef.Context, Enum);
+  if (Owner->isFunctionOrMethod())
+    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Enum);
   Enum->startDefinition();
 
   llvm::SmallVector<Sema::DeclPtrTy, 16> Enumerators;
@@ -276,6 +281,8 @@
     Record->setInstantiationOfMemberClass(D);
 
   Owner->addDecl(SemaRef.Context, Record);
+  if (Owner->isFunctionOrMethod())
+    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Record);
   return Record;
 }
 

Modified: cfe/trunk/test/SemaTemplate/instantiate-declref.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-declref.cpp?rev=72526&r1=72525&r2=72526&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-declref.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-declref.cpp Thu May 28 11:34:51 2009
@@ -1,5 +1,4 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-
 namespace N {
   struct Outer {
     struct Inner {





More information about the cfe-commits mailing list