[cfe-commits] r131036 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaObjCXX/namespace-lookup.mm

Douglas Gregor dgregor at apple.com
Fri May 6 16:28:47 PDT 2011


Author: dgregor
Date: Fri May  6 18:28:47 2011
New Revision: 131036

URL: http://llvm.org/viewvc/llvm-project?rev=131036&view=rev
Log:
When checking for a prior declaration of the name of a namespace, skip
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>).

Added:
    cfe/trunk/test/SemaObjCXX/namespace-lookup.mm
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=131036&r1=131035&r2=131036&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri May  6 18:28:47 2011
@@ -3730,10 +3730,21 @@
     //   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()) {

Added: cfe/trunk/test/SemaObjCXX/namespace-lookup.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/namespace-lookup.mm?rev=131036&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/namespace-lookup.mm (added)
+++ cfe/trunk/test/SemaObjCXX/namespace-lookup.mm Fri May  6 18:28:47 2011
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// <rdar://problem/9388207>
+ at interface A
+ at end
+
+ at interface A(N)
+ at end
+
+ at protocol M
+ at end
+
+namespace N { }
+namespace M { }





More information about the cfe-commits mailing list