]> granicus.if.org Git - clang/commitdiff
When checking for a prior declaration of the name of a namespace, skip
authorDouglas Gregor <dgregor@apple.com>
Fri, 6 May 2011 23:28:47 +0000 (23:28 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 6 May 2011 23:28:47 +0000 (23:28 +0000)
any names that aren't in the appropriate identifier namespaces. Fixes
an embarrassing bug where we give a redefinition error due to an
Objective-C category (<rdar://problem/9388207>).

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

lib/Sema/SemaDeclCXX.cpp
test/SemaObjCXX/namespace-lookup.mm [new file with mode: 0644]

index bc6584bc736efc1e92c70a8850fbe96760147c8c..df08ed8f89cbe88d5185eefab4c881b76101da43 100644 (file)
@@ -3730,10 +3730,21 @@ Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
     //   treated as an original-namespace-name.
     //
     // Since namespace names are unique in their scope, and we don't
-    // look through using directives, just
-    DeclContext::lookup_result R = CurContext->getRedeclContext()->lookup(II);
-    NamedDecl *PrevDecl = R.first == R.second? 0 : *R.first;
-
+    // look through using directives, just look for any ordinary names.
+    
+    const unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Member | 
+      Decl::IDNS_Type | Decl::IDNS_Using | Decl::IDNS_Tag | 
+      Decl::IDNS_Namespace;
+    NamedDecl *PrevDecl = 0;
+    for (DeclContext::lookup_result R 
+            = CurContext->getRedeclContext()->lookup(II);
+         R.first != R.second; ++R.first) {
+      if ((*R.first)->getIdentifierNamespace() & IDNS) {
+        PrevDecl = *R.first;
+        break;
+      }
+    }
+    
     if (NamespaceDecl *OrigNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl)) {
       // This is an extended namespace definition.
       if (Namespc->isInline() != OrigNS->isInline()) {
diff --git a/test/SemaObjCXX/namespace-lookup.mm b/test/SemaObjCXX/namespace-lookup.mm
new file mode 100644 (file)
index 0000000..205b443
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// <rdar://problem/9388207>
+@interface A
+@end
+
+@interface A(N)
+@end
+
+@protocol M
+@end
+
+namespace N { }
+namespace M { }