r225780 - Sema: An extern declaration can't be a redeclaration of a parameter
David Majnemer
david.majnemer at gmail.com
Tue Jan 13 01:55:56 PST 2015
Author: majnemer
Date: Tue Jan 13 03:55:56 2015
New Revision: 225780
URL: http://llvm.org/viewvc/llvm-project?rev=225780&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/private-extern.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=225780&r1=225779&r2=225780&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan 13 03:55:56 2015
@@ -3282,14 +3282,12 @@ void Sema::MergeVarDecl(VarDecl *New, Lo
}
// Check if extern is followed by non-extern and vice-versa.
- if (New->hasExternalStorage() &&
- !Old->hasLinkage() && Old->isLocalVarDecl()) {
+ if (New->hasGlobalStorage() && !Old->hasLinkage() && Old->hasLocalStorage()) {
Diag(New->getLocation(), diag::err_extern_non_extern) << New->getDeclName();
Diag(OldLocation, PrevDiag);
return New->setInvalidDecl();
}
- if (Old->hasLinkage() && New->isLocalVarDecl() &&
- !New->hasExternalStorage()) {
+ if (Old->hasGlobalStorage() && !New->hasLinkage() && New->hasLocalStorage()) {
Diag(New->getLocation(), diag::err_non_extern_extern) << New->getDeclName();
Diag(OldLocation, PrevDiag);
return New->setInvalidDecl();
Modified: cfe/trunk/test/Sema/private-extern.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/private-extern.c?rev=225780&r1=225779&r2=225780&view=diff
==============================================================================
--- cfe/trunk/test/Sema/private-extern.c (original)
+++ cfe/trunk/test/Sema/private-extern.c Tue Jan 13 03:55:56 2015
@@ -83,3 +83,7 @@ __private_extern__ int g19;
int g19 = 0;
__private_extern__ int g20 = 0;
+
+void f10(int g20) { // expected-note{{previous definition is here}}
+ extern int g20; // expected-error{{extern declaration of 'g20' follows non-extern declaration}}
+}
More information about the cfe-commits
mailing list