]> granicus.if.org Git - clang/commitdiff
C++ [basic.scope.hiding] allows an ordinary name to hide a non-tag
authorDouglas Gregor <dgregor@apple.com>
Sat, 23 Oct 2010 16:06:17 +0000 (16:06 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 23 Oct 2010 16:06:17 +0000 (16:06 +0000)
name *in the same scope*, but not across scopes. Implement the
highlighted condition.

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

lib/Sema/SemaLookup.cpp
test/CXX/basic/basic.scope/basic.scope.hiding/p2.cpp [new file with mode: 0644]

index cc27e35bb089d233bb5fc6743e9d644e14509bec..67d22ee924197d97e341cef31c3b9c51e5a1d389 100644 (file)
@@ -407,8 +407,13 @@ void LookupResult::resolveKind() {
   // But it's still an error if there are distinct tag types found,
   // even if they're not visible. (ref?)
   if (HideTags && HasTag && !Ambiguous &&
-      (HasFunction || HasNonFunction || HasUnresolved))
-    Decls[UniqueTagIndex] = Decls[--N];
+      (HasFunction || HasNonFunction || HasUnresolved)) {
+    if (Decls[UniqueTagIndex]->getDeclContext()->getRedeclContext()->Equals(
+         Decls[UniqueTagIndex? 0 : N-1]->getDeclContext()->getRedeclContext()))
+      Decls[UniqueTagIndex] = Decls[--N];
+    else
+      Ambiguous = true;
+  }
 
   Decls.set_size(N);
 
diff --git a/test/CXX/basic/basic.scope/basic.scope.hiding/p2.cpp b/test/CXX/basic/basic.scope/basic.scope.hiding/p2.cpp
new file mode 100644 (file)
index 0000000..911df98
--- /dev/null
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// rdar4641403
+namespace N {
+  struct X { // expected-note{{candidate found by name lookup}}
+    float b;
+  };
+}
+
+using namespace N;
+
+typedef struct {
+  int a;
+} X; // expected-note{{candidate found by name lookup}}
+
+
+struct Y { };
+void Y(int) { }
+
+void f() {
+  X *x; // expected-error{{reference to 'X' is ambiguous}}
+  Y(1); // okay
+}
+