[cfe-commits] r124579 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/private-extern.c
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Jan 30 23:04:47 PST 2011
Author: akirtzidis
Date: Mon Jan 31 01:04:46 2011
New Revision: 124579
URL: http://llvm.org/viewvc/llvm-project?rev=124579&view=rev
Log:
Diagnose if extern local variable is followed by non-extern and vice-versa.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/private-extern.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=124579&r1=124578&r2=124579&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 31 01:04:46 2011
@@ -1963,6 +1963,10 @@
"static declaration of %0 follows non-static declaration">;
def err_non_static_static : Error<
"non-static declaration of %0 follows static declaration">;
+def err_extern_non_extern : Error<
+ "extern declaration of %0 follows non-extern declaration">;
+def err_non_extern_extern : Error<
+ "non-extern declaration of %0 follows extern declaration">;
def err_non_thread_thread : Error<
"non-thread-local declaration of %0 follows thread-local declaration">;
def err_thread_non_thread : Error<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=124579&r1=124578&r2=124579&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 31 01:04:46 2011
@@ -1548,6 +1548,20 @@
return New->setInvalidDecl();
}
+ // Check if extern is followed by non-extern and vice-versa.
+ if (New->hasExternalStorage() &&
+ !Old->hasLinkage() && Old->isLocalVarDecl()) {
+ Diag(New->getLocation(), diag::err_extern_non_extern) << New->getDeclName();
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ return New->setInvalidDecl();
+ }
+ if (Old->hasExternalStorage() &&
+ !New->hasLinkage() && New->isLocalVarDecl()) {
+ Diag(New->getLocation(), diag::err_non_extern_extern) << New->getDeclName();
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ return New->setInvalidDecl();
+ }
+
// Variables with external linkage are analyzed in FinalizeDeclaratorGroup.
// FIXME: The test for external storage here seems wrong? We still
Modified: cfe/trunk/test/Sema/private-extern.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/private-extern.c?rev=124579&r1=124578&r2=124579&view=diff
==============================================================================
--- cfe/trunk/test/Sema/private-extern.c (original)
+++ cfe/trunk/test/Sema/private-extern.c Mon Jan 31 01:04:46 2011
@@ -19,27 +19,23 @@
static int g5; // expected-error{{static declaration of 'g5' follows non-static declaration}}
void f0() {
- // FIXME: Diagnose this?
- int g6;
- extern int g6;
+ int g6; // expected-note {{previous}}
+ extern int g6; // expected-error {{extern declaration of 'g6' follows non-extern declaration}}
}
void f1() {
- // FIXME: Diagnose this?
- int g7;
- __private_extern__ int g7;
+ int g7; // expected-note {{previous}}
+ __private_extern__ int g7; // expected-error {{extern declaration of 'g7' follows non-extern declaration}}
}
void f2() {
extern int g8; // expected-note{{previous definition}}
- // FIXME: Improve this diagnostic.
- int g8; // expected-error{{redefinition of 'g8'}}
+ int g8; // expected-error {{non-extern declaration of 'g8' follows extern declaration}}
}
void f3() {
__private_extern__ int g9; // expected-note{{previous definition}}
- // FIXME: Improve this diagnostic.
- int g9; // expected-error{{redefinition of 'g9'}}
+ int g9; // expected-error {{non-extern declaration of 'g9' follows extern declaration}}
}
void f4() {
More information about the cfe-commits
mailing list