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.
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

View 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:

View 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() {} }