]> granicus.if.org Git - clang/commitdiff
When performing unqualified name lookup in C++, don't look directly
authorDouglas Gregor <dgregor@apple.com>
Tue, 8 Dec 2009 15:38:36 +0000 (15:38 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 8 Dec 2009 15:38:36 +0000 (15:38 +0000)
into transparent contexts; instead, we'll look into their nearest
enclosing non-transparent contexts further up the stack. Fixes PR5479.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90859 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLookup.cpp
test/SemaCXX/linkage-spec.cpp
test/SemaCXX/using-directive.cpp

index 1ddfef839fd64d15d7e5bc97f4e495a3325350c9..48d7320d2e96fdd0dd800c32d203d466caae5d76 100644 (file)
@@ -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.
index fc9b3ab51eadc3ad95db32ca4fac174f4017e458..d19727ac0766c461ed4af1315feda028d3f62b82 100644 (file)
@@ -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);
+    }
+}
index 51f347dc7a73a737a964516895fa165a234b7282..b7583f27cb64ed7074bcfb9a3b939a7d39c8d5cc 100644 (file)
@@ -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); }