[cfe-commits] r86461 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/linkage-spec.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sun Nov 8 03:36:55 PST 2009


Author: cornedbee
Date: Sun Nov  8 05:36:54 2009
New Revision: 86461

URL: http://llvm.org/viewvc/llvm-project?rev=86461&view=rev
Log:
When checking the namespace of a redeclaration or definition, look through linkage specs. Fixes PR5430.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/linkage-spec.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=86461&r1=86460&r2=86461&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Nov  8 05:36:54 2009
@@ -1839,17 +1839,22 @@
     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();
+      }
     }
   }
 

Modified: cfe/trunk/test/SemaCXX/linkage-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/linkage-spec.cpp?rev=86461&r1=86460&r2=86461&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/linkage-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/linkage-spec.cpp Sun Nov  8 05:36:54 2009
@@ -33,3 +33,10 @@
     };
   }
 }
+
+// PR5430
+namespace pr5430 {
+  extern "C" void func(void);
+}
+using namespace pr5430;
+extern "C" void pr5430::func(void) { }





More information about the cfe-commits mailing list