From: Sebastian Redl Date: Sun, 8 Nov 2009 11:36:54 +0000 (+0000) Subject: When checking the namespace of a redeclaration or definition, look through linkage... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9770ef0eea1dbebb9cad93b8a564bff789568e62;p=clang When checking the namespace of a redeclaration or definition, look through linkage specs. Fixes PR5430. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86461 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 8e1a19cbe5..cfea66bf5a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1839,17 +1839,22 @@ Sema::HandleDeclarator(Scope *S, Declarator &D, if (isa(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(CurContext)) - Diag(L, diag::err_invalid_declarator_in_function) << Name << R; - else - Diag(L, diag::err_invalid_declarator_scope) - << Name << cast(DC) << R; - D.setInvalidType(); + } else { + DeclContext *Cur = CurContext; + while (isa(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(Cur)) + Diag(L, diag::err_invalid_declarator_in_function) << Name << R; + else + Diag(L, diag::err_invalid_declarator_scope) + << Name << cast(DC) << R; + D.setInvalidType(); + } } } diff --git a/test/SemaCXX/linkage-spec.cpp b/test/SemaCXX/linkage-spec.cpp index 53cd61c7f5..fc9b3ab51e 100644 --- a/test/SemaCXX/linkage-spec.cpp +++ b/test/SemaCXX/linkage-spec.cpp @@ -33,3 +33,10 @@ extern "C++" { }; } } + +// PR5430 +namespace pr5430 { + extern "C" void func(void); +} +using namespace pr5430; +extern "C" void pr5430::func(void) { }