aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-01-31 07:04:50 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-01-31 07:04:50 +0000
commit49a61727986332f2eba61fb2657800d76c5a4bb9 (patch)
treef0d4b10de2d5379aac782852fc63f373cc25a8a3 /lib/Sema/SemaDecl.cpp
parent6684d85e9075e3c1750d911c69a517145a82a410 (diff)
Fix the diagnostic when we are shadowing an external variable and there exists a locally scoped extern with the same name.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124580 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 24307c98a9..253f1dcde8 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3129,21 +3129,32 @@ void Sema::CheckShadow(Scope *S, VarDecl *D, const LookupResult& R) {
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.