When checking the namespace of a redeclaration or definition, look through linkage specs. Fixes PR5430.

llvm-svn: 86461
This commit is contained in:
Sebastian Redl 2009-11-08 11:36:54 +00:00
parent 3752e1dbb4
commit afb8be743d
2 changed files with 23 additions and 11 deletions

View 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();
}
}
}

View File

@ -33,3 +33,10 @@ extern "C++" {
};
}
}
// PR5430
namespace pr5430 {
extern "C" void func(void);
}
using namespace pr5430;
extern "C" void pr5430::func(void) { }