[cfe-commits] r124580 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/warn-shadow.c
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Jan 30 23:04:51 PST 2011
Author: akirtzidis
Date: Mon Jan 31 01:04:50 2011
New Revision: 124580
URL: http://llvm.org/viewvc/llvm-project?rev=124580&view=rev
Log:
Fix the diagnostic when we are shadowing an external variable and there exists a locally scoped extern with the same name.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/warn-shadow.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=124580&r1=124579&r2=124580&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 31 01:04:50 2011
@@ -3129,21 +3129,32 @@
if (!isa<VarDecl>(ShadowedDecl) && !isa<FieldDecl>(ShadowedDecl))
return;
- DeclContext *OldDC = ShadowedDecl->getDeclContext();
-
- // Don't warn for this case:
- //
- // @code
- // extern int bob;
- // void f() {
- // extern int bob;
- // }
- // @endcode
- if (D->isExternC() && NewDC->isFunctionOrMethod())
- if (VarDecl *shadowedVar = dyn_cast<VarDecl>(ShadowedDecl))
- if (shadowedVar->isExternC())
+ if (VarDecl *shadowedVar = dyn_cast<VarDecl>(ShadowedDecl))
+ if (shadowedVar->isExternC()) {
+ // Don't warn for this case:
+ //
+ // @code
+ // extern int bob;
+ // void f() {
+ // extern int bob;
+ // }
+ // @endcode
+ if (D->isExternC())
return;
+ // For shadowing external vars, make sure that we point to the global
+ // declaration, not a locally scoped extern declaration.
+ for (VarDecl::redecl_iterator
+ I = shadowedVar->redecls_begin(), E = shadowedVar->redecls_end();
+ I != E; ++I)
+ if (I->isFileVarDecl()) {
+ ShadowedDecl = *I;
+ break;
+ }
+ }
+
+ DeclContext *OldDC = ShadowedDecl->getDeclContext();
+
// Only warn about certain kinds of shadowing for class members.
if (NewDC && NewDC->isRecord()) {
// In particular, don't warn about shadowing non-class members.
Modified: cfe/trunk/test/Sema/warn-shadow.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-shadow.c?rev=124580&r1=124579&r2=124580&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-shadow.c (original)
+++ cfe/trunk/test/Sema/warn-shadow.c Mon Jan 31 01:04:50 2011
@@ -49,8 +49,13 @@
void test6(void (*f)(int i)) {}
void test7(void *context, void (*callback)(void *context)) {}
+extern int bob; // expected-note {{previous declaration is here}}
+
// rdar://8883302
-extern int bob;
void rdar8883302() {
extern int bob; // don't warn for shadowing.
}
+
+void test8() {
+ int bob; // expected-warning {{declaration shadows a variable in the global scope}}
+}
More information about the cfe-commits
mailing list