]> granicus.if.org Git - clang/commitdiff
When checking the namespace of a redeclaration or definition, look through linkage...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Sun, 8 Nov 2009 11:36:54 +0000 (11:36 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Sun, 8 Nov 2009 11:36:54 +0000 (11:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86461 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/linkage-spec.cpp

index 8e1a19cbe5c9d3e0c55cb19071e7cc81e3a5a9ba..cfea66bf5af4a7ff46fafb53639d75d4d103ff05 100644 (file)
@@ -1839,17 +1839,22 @@ Sema::HandleDeclarator(Scope *S, Declarator &D,
     if (isa<TranslationUnitDecl>(DC)) {
       Diag(D.getIdentifierLoc(), diag::err_invalid_declarator_global_scope)
         << Name << D.getCXXScopeSpec().getRange();
-    } else if (!CurContext->Encloses(DC)) {
-      // The qualifying scope doesn't enclose the original declaration.
-      // Emit diagnostic based on current scope.
-      SourceLocation L = D.getIdentifierLoc();
-      SourceRange R = D.getCXXScopeSpec().getRange();
-      if (isa<FunctionDecl>(CurContext))
-        Diag(L, diag::err_invalid_declarator_in_function) << Name << R;
-      else
-        Diag(L, diag::err_invalid_declarator_scope)
-          << Name << cast<NamedDecl>(DC) << R;
-      D.setInvalidType();
+    } else {
+      DeclContext *Cur = CurContext;
+      while (isa<LinkageSpecDecl>(Cur))
+        Cur = Cur->getParent();
+      if (!Cur->Encloses(DC)) {
+        // The qualifying scope doesn't enclose the original declaration.
+        // Emit diagnostic based on current scope.
+        SourceLocation L = D.getIdentifierLoc();
+        SourceRange R = D.getCXXScopeSpec().getRange();
+        if (isa<FunctionDecl>(Cur))
+          Diag(L, diag::err_invalid_declarator_in_function) << Name << R;
+        else
+          Diag(L, diag::err_invalid_declarator_scope)
+            << Name << cast<NamedDecl>(DC) << R;
+        D.setInvalidType();
+      }
     }
   }
 
index 53cd61c7f50b9dfeb4868c60a9e1b12caa97540f..fc9b3ab51eadc3ad95db32ca4fac174f4017e458 100644 (file)
@@ -33,3 +33,10 @@ extern "C++" {
     };
   }
 }
+
+// PR5430
+namespace pr5430 {
+  extern "C" void func(void);
+}
+using namespace pr5430;
+extern "C" void pr5430::func(void) { }