From a64c1e5452dea9d227276c21e5457ccd30a202c1 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 8 Dec 2009 15:38:36 +0000 Subject: [PATCH] When performing unqualified name lookup in C++, don't look directly into transparent contexts; instead, we'll look into their nearest enclosing non-transparent contexts further up the stack. Fixes PR5479. llvm-svn: 90859 --- clang/lib/Sema/SemaLookup.cpp | 7 ++++++- clang/test/SemaCXX/linkage-spec.cpp | 14 ++++++++++++++ clang/test/SemaCXX/using-directive.cpp | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 1ddfef839fd6..48d7320d2e96 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -480,7 +480,12 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) { DeclContext *OuterCtx = findOuterContext(S); for (; Ctx && Ctx->getPrimaryContext() != OuterCtx; Ctx = Ctx->getLookupParent()) { - if (Ctx->isFunctionOrMethod()) + // We do not directly look into function or method contexts + // (since all local variables are found via the identifier + // changes) or in transparent contexts (since those entities + // will be found in the nearest enclosing non-transparent + // context). + if (Ctx->isFunctionOrMethod() || Ctx->isTransparentContext()) continue; // Perform qualified name lookup into this context. diff --git a/clang/test/SemaCXX/linkage-spec.cpp b/clang/test/SemaCXX/linkage-spec.cpp index fc9b3ab51ead..d19727ac0766 100644 --- a/clang/test/SemaCXX/linkage-spec.cpp +++ b/clang/test/SemaCXX/linkage-spec.cpp @@ -40,3 +40,17 @@ namespace pr5430 { } using namespace pr5430; extern "C" void pr5430::func(void) { } + +// PR5404 +int f2(char *) +{ + return 0; +} + +extern "C" +{ + int f2(int) + { + return f2((char *)0); + } +} diff --git a/clang/test/SemaCXX/using-directive.cpp b/clang/test/SemaCXX/using-directive.cpp index 51f347dc7a73..b7583f27cb64 100644 --- a/clang/test/SemaCXX/using-directive.cpp +++ b/clang/test/SemaCXX/using-directive.cpp @@ -112,3 +112,12 @@ using namespace Alias; void testAlias() { inAliased(); } + +namespace N { void f2(int); } + +extern "C++" { + using namespace N; + void f3() { f2(1); } +} + +void f4() { f2(1); }