summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
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
commit857dd066052e0883ca1f9da42883e9ab8367fb88 (patch)
tree1c1630150c6156ff7d5d5137594b5eebd89129e1 /clang/lib/Sema
parent819f610942163a1f17d507c202042138e48f3cc2 (diff)
downloadbcm5719-llvm-857dd066052e0883ca1f9da42883e9ab8367fb88.tar.gz
bcm5719-llvm-857dd066052e0883ca1f9da42883e9ab8367fb88.zip
Fix the diagnostic when we are shadowing an external variable and there exists a locally scoped extern with the same name.
llvm-svn: 124580
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 24307c98a97..253f1dcde87 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/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.
OpenPOWER on IntegriCloud