]> granicus.if.org Git - clang/commitdiff
Introduced DeclContext::isDependentContext, which determines whether a
authorDouglas Gregor <dgregor@apple.com>
Thu, 28 May 2009 16:34:51 +0000 (16:34 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 28 May 2009 16:34:51 +0000 (16:34 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72526 91177308-0d34-0410-b5e6-96231b3b80d8

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

index eb38367436bd369050768024e0bf367a35f41e9a..e134aed73d770d3d8cab778e629a153613652eeb 100644 (file)
@@ -1081,7 +1081,7 @@ public:
   /// \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.
   /// 
index 7d88cf228fc8ae627065cbf7aa7c8532d71655fd..271e59aadc3df4e2a91503fad54812c8a21c4cf1 100644 (file)
@@ -441,6 +441,10 @@ public:
     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
index 6c620713f763d4162d8e9e4d40e20d18cc3bba0d..063914092ee563dfade8bade76cf69c5aedfe14a 100644 (file)
@@ -528,19 +528,6 @@ OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const {
 // 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);
index 071fb791013ddaa29ceca575d5c7ac2270352274..ba8f3351c3a9c7ec92de14583eb19de8aefd9ec2 100644 (file)
@@ -396,6 +396,21 @@ void DeclContext::DestroyDecls(ASTContext &C) {
     (*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
index 33eedcec38a486a99dd8ce0a1498e7138ff30f73..39e455a6ec7d91722660e6f0d31b7e3f244f069f 100644 (file)
@@ -97,6 +97,9 @@ Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
     Typedef->setInvalidDecl();
 
   Owner->addDecl(SemaRef.Context, Typedef);
+  if (Owner->isFunctionOrMethod())
+    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Typedef);
+    
   return Typedef;
 }
 
@@ -211,6 +214,8 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
   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 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
     Record->setInstantiationOfMemberClass(D);
 
   Owner->addDecl(SemaRef.Context, Record);
+  if (Owner->isFunctionOrMethod())
+    SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Record);
   return Record;
 }
 
index 1a5f21663994b7196e5ef18ba7e4de935271cfd8..e49d330f63d41ad0f8e7cfa051cd8af0a77ac499 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-
 namespace N {
   struct Outer {
     struct Inner {