]> granicus.if.org Git - clang/commitdiff
When checking whether one declaration context encloses another, make sure to look...
authorDouglas Gregor <dgregor@apple.com>
Thu, 27 Aug 2009 06:03:53 +0000 (06:03 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 27 Aug 2009 06:03:53 +0000 (06:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80212 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
lib/AST/DeclBase.cpp
test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp

index 0979733644a5f6984d7628842969737fede07b91..e43f15d79a7c947edce6216e72c1f5777aca8972 100644 (file)
@@ -578,12 +578,9 @@ public:
   /// inline namespaces.
   bool isTransparentContext() const;
 
-  bool Encloses(DeclContext *DC) const {
-    for (; DC; DC = DC->getParent())
-      if (DC == this)
-        return true;
-    return false;
-  }
+  /// \brief Determine whether this declaration context encloses the
+  /// declaration context DC.
+  bool Encloses(DeclContext *DC);
 
   /// getPrimaryContext - There may be many different
   /// declarations of the same entity (including forward declarations
index 8296f2931b8a766b16c3cbd848bf8af24c758286..cd5b0063a63ed1869b8dcde84696ae0f2f7aca2c 100644 (file)
@@ -448,6 +448,16 @@ bool DeclContext::isTransparentContext() const {
   return false;
 }
 
+bool DeclContext::Encloses(DeclContext *DC) {
+  if (getPrimaryContext() != this)
+    return getPrimaryContext()->Encloses(DC);
+  
+  for (; DC; DC = DC->getParent())
+    if (DC->getPrimaryContext() == this)
+      return true;
+  return false;  
+}
+
 DeclContext *DeclContext::getPrimaryContext() {
   switch (DeclKind) {
   case Decl::TranslationUnit:
index 28a5d98540733a4f3e96cd23e242b02543fd9cd5..725b61c271624807a5750d3efb6dec9888f02edb 100644 (file)
@@ -63,3 +63,6 @@ template<typename T, typename U>
 X0<T, U>::operator T*() const {
   return &value;
 }
+
+namespace N { template <class X> class A {void a();}; }
+namespace N { template <class X> void A<X>::a() {} }