summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-04-30 07:08:38 +0000
committerDouglas Gregor <dgregor@apple.com>2010-04-30 07:08:38 +0000
commit8b895228d91c0e0d0ab541dc8d7ce8ac8f9b3c15 (patch)
tree7261e3f074058277c07ccb0407cd018ef5803e62
parent5f2314f3a3b6fbf96478bc38ea30abb336404017 (diff)
downloadbcm5719-llvm-8b895228d91c0e0d0ab541dc8d7ce8ac8f9b3c15.tar.gz
bcm5719-llvm-8b895228d91c0e0d0ab541dc8d7ce8ac8f9b3c15.zip
Fix ADL for types declared in transparent decls, from Alp Toker!
llvm-svn: 102695
-rw-r--r--clang/lib/Sema/SemaLookup.cpp34
-rw-r--r--clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp15
2 files changed, 31 insertions, 18 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 1b2401a80cb..bdbbc119c61 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1386,10 +1386,18 @@ addAssociatedClassesAndNamespaces(QualType T,
Sema::AssociatedNamespaceSet &AssociatedNamespaces,
Sema::AssociatedClassSet &AssociatedClasses);
-static void CollectNamespace(Sema::AssociatedNamespaceSet &Namespaces,
- DeclContext *Ctx) {
+static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet &Namespaces,
+ DeclContext *Ctx) {
+ // Add the associated namespace for this class.
+
+ // We don't use DeclContext::getEnclosingNamespaceContext() as this may
+ // be a locally scoped record.
+
+ while (Ctx->isRecord() || Ctx->isTransparentContext())
+ Ctx = Ctx->getParent();
+
if (Ctx->isFileContext())
- Namespaces.insert(Ctx);
+ Namespaces.insert(Ctx->getPrimaryContext());
}
// \brief Add the associated classes and namespaces for argument-dependent
@@ -1425,9 +1433,7 @@ addAssociatedClassesAndNamespaces(const TemplateArgument &Arg,
if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
AssociatedClasses.insert(EnclosingClass);
// Add the associated namespace for this class.
- while (Ctx->isRecord())
- Ctx = Ctx->getParent();
- CollectNamespace(AssociatedNamespaces, Ctx);
+ CollectEnclosingNamespace(AssociatedNamespaces, Ctx);
}
break;
}
@@ -1471,9 +1477,7 @@ addAssociatedClassesAndNamespaces(CXXRecordDecl *Class,
if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
AssociatedClasses.insert(EnclosingClass);
// Add the associated namespace for this class.
- while (Ctx->isRecord())
- Ctx = Ctx->getParent();
- CollectNamespace(AssociatedNamespaces, Ctx);
+ CollectEnclosingNamespace(AssociatedNamespaces, Ctx);
// Add the class itself. If we've already seen this class, we don't
// need to visit base classes.
@@ -1495,9 +1499,7 @@ addAssociatedClassesAndNamespaces(CXXRecordDecl *Class,
if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
AssociatedClasses.insert(EnclosingClass);
// Add the associated namespace for this class.
- while (Ctx->isRecord())
- Ctx = Ctx->getParent();
- CollectNamespace(AssociatedNamespaces, Ctx);
+ CollectEnclosingNamespace(AssociatedNamespaces, Ctx);
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
@@ -1538,9 +1540,7 @@ addAssociatedClassesAndNamespaces(CXXRecordDecl *Class,
if (AssociatedClasses.insert(BaseDecl)) {
// Find the associated namespace for this base class.
DeclContext *BaseCtx = BaseDecl->getDeclContext();
- while (BaseCtx->isRecord())
- BaseCtx = BaseCtx->getParent();
- CollectNamespace(AssociatedNamespaces, BaseCtx);
+ CollectEnclosingNamespace(AssociatedNamespaces, BaseCtx);
// Make sure we visit the bases of this base class.
if (BaseDecl->bases_begin() != BaseDecl->bases_end())
@@ -1615,9 +1615,7 @@ addAssociatedClassesAndNamespaces(QualType T,
AssociatedClasses.insert(EnclosingClass);
// Add the associated namespace for this class.
- while (Ctx->isRecord())
- Ctx = Ctx->getParent();
- CollectNamespace(AssociatedNamespaces, Ctx);
+ CollectEnclosingNamespace(AssociatedNamespaces, Ctx);
return;
}
diff --git a/clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp b/clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
index ee01416c7b1..0e262f3eb1d 100644
--- a/clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
+++ b/clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
@@ -71,3 +71,18 @@ namespace O {
}
}
+extern "C" {
+ struct L { };
+}
+
+void h(L); // expected-note{{candidate function}}
+
+namespace P {
+ void h(L); // expected-note{{candidate function}}
+ void test_transparent_context_adl(L l) {
+ {
+ h(l); // expected-error {{call to 'h' is ambiguous}}
+ }
+ }
+}
+
OpenPOWER on IntegriCloud