When checking whether one declaration context encloses another, make sure to look at the primary contexts. Thanks to Eli for the test case

llvm-svn: 80212
This commit is contained in:
Douglas Gregor 2009-08-27 06:03:53 +00:00
parent 35d6e3e710
commit e985a3b724
3 changed files with 16 additions and 6 deletions

View File

@ -578,12 +578,9 @@ public:
/// inline namespaces. /// inline namespaces.
bool isTransparentContext() const; bool isTransparentContext() const;
bool Encloses(DeclContext *DC) const { /// \brief Determine whether this declaration context encloses the
for (; DC; DC = DC->getParent()) /// declaration context DC.
if (DC == this) bool Encloses(DeclContext *DC);
return true;
return false;
}
/// getPrimaryContext - There may be many different /// getPrimaryContext - There may be many different
/// declarations of the same entity (including forward declarations /// declarations of the same entity (including forward declarations

View File

@ -448,6 +448,16 @@ bool DeclContext::isTransparentContext() const {
return false; 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() { DeclContext *DeclContext::getPrimaryContext() {
switch (DeclKind) { switch (DeclKind) {
case Decl::TranslationUnit: case Decl::TranslationUnit:

View File

@ -63,3 +63,6 @@ template<typename T, typename U>
X0<T, U>::operator T*() const { X0<T, U>::operator T*() const {
return &value; return &value;
} }
namespace N { template <class X> class A {void a();}; }
namespace N { template <class X> void A<X>::a() {} }