[cfe-commits] r80212 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp
Douglas Gregor
dgregor at apple.com
Wed Aug 26 23:03:53 PDT 2009
Author: dgregor
Date: Thu Aug 27 01:03:53 2009
New Revision: 80212
URL: http://llvm.org/viewvc/llvm-project?rev=80212&view=rev
Log:
When checking whether one declaration context encloses another, make sure to look at the primary contexts. Thanks to Eli for the test case
Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp
Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=80212&r1=80211&r2=80212&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Aug 27 01:03:53 2009
@@ -578,12 +578,9 @@
/// 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
Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=80212&r1=80211&r2=80212&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Aug 27 01:03:53 2009
@@ -448,6 +448,16 @@
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:
Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp?rev=80212&r1=80211&r2=80212&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp Thu Aug 27 01:03:53 2009
@@ -63,3 +63,6 @@
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() {} }
More information about the cfe-commits
mailing list