forked from OSchip/llvm-project
Sema: An extern declaration can't be a redeclaration of a parameter
In the following: void f(int x) { extern int x; } The second declaration of 'x' shouldn't be considered a redeclaration of the parameter. This is a different approach to r225780. llvm-svn: 225875
This commit is contained in:
parent
11f5032368
commit
a3b04cea04
|
@ -906,6 +906,11 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
/// \brief Similar to isLocalVarDecl but also includes parameters.
|
||||
bool isLocalVarDeclOrParm() const {
|
||||
return isLocalVarDecl() || getKind() == Decl::ParmVar;
|
||||
}
|
||||
|
||||
/// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but
|
||||
/// excludes variables declared in blocks.
|
||||
bool isFunctionOrMethodVarDecl() const {
|
||||
|
|
|
@ -3285,12 +3285,12 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
|
|||
|
||||
// Check if extern is followed by non-extern and vice-versa.
|
||||
if (New->hasExternalStorage() &&
|
||||
!Old->hasLinkage() && Old->isLocalVarDecl()) {
|
||||
!Old->hasLinkage() && Old->isLocalVarDeclOrParm()) {
|
||||
Diag(New->getLocation(), diag::err_extern_non_extern) << New->getDeclName();
|
||||
Diag(OldLocation, PrevDiag);
|
||||
return New->setInvalidDecl();
|
||||
}
|
||||
if (Old->hasLinkage() && New->isLocalVarDecl() &&
|
||||
if (Old->hasLinkage() && New->isLocalVarDeclOrParm() &&
|
||||
!New->hasExternalStorage()) {
|
||||
Diag(New->getLocation(), diag::err_non_extern_extern) << New->getDeclName();
|
||||
Diag(OldLocation, PrevDiag);
|
||||
|
|
|
@ -60,3 +60,7 @@ int *p=&g19; // expected-error{{use of undeclared identifier 'g19'}} \
|
|||
static int a;
|
||||
extern int a; // expected-note {{previous declaration is here}}
|
||||
int a; // expected-error {{non-static declaration of 'a' follows static declaration}}
|
||||
|
||||
void f(int x) { // expected-note {{previous definition is here}}
|
||||
extern int x; // expected-error {{extern declaration of 'x' follows non-extern declaration}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue