summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-25 21:39:50 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-25 21:39:50 +0000
commitbd0a3fe5e8d25ed888fe1e1a63d8ff51e15f4ae6 (patch)
tree378bfcc15c0d223593053c886cd14d543eef4f1b
parent7be2542fc90eee4e66f33d4e59cc8ca800cfa555 (diff)
downloadbcm5719-llvm-bd0a3fe5e8d25ed888fe1e1a63d8ff51e15f4ae6.tar.gz
bcm5719-llvm-bd0a3fe5e8d25ed888fe1e1a63d8ff51e15f4ae6.zip
'extern' variables in functions don't shadow externs in global scope. Fixes rdar://8883302, this time for C++ as well.
llvm-svn: 130157
-rw-r--r--clang/lib/Sema/SemaDecl.cpp18
-rw-r--r--clang/test/SemaCXX/warn-shadow.cpp11
2 files changed, 15 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d07bd4b72d3..200f8ce0379 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3664,10 +3664,11 @@ void Sema::CheckShadow(Scope *S, VarDecl *D, const LookupResult& R) {
return;
// Don't diagnose declarations at file scope.
- DeclContext *NewDC = D->getDeclContext();
- if (NewDC->isFileContext())
+ if (D->hasGlobalStorage())
return;
-
+
+ DeclContext *NewDC = D->getDeclContext();
+
// Only diagnose if we're shadowing an unambiguous field or variable.
if (R.getResultKind() != LookupResult::Found)
return;
@@ -3684,17 +3685,6 @@ void Sema::CheckShadow(Scope *S, VarDecl *D, const LookupResult& R) {
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
diff --git a/clang/test/SemaCXX/warn-shadow.cpp b/clang/test/SemaCXX/warn-shadow.cpp
index 3bf9af414db..68e9467a937 100644
--- a/clang/test/SemaCXX/warn-shadow.cpp
+++ b/clang/test/SemaCXX/warn-shadow.cpp
@@ -70,3 +70,14 @@ struct S {
}
};
}
+
+extern int bob; // expected-note {{previous declaration is here}}
+
+// rdar://8883302
+void rdar8883302() {
+ extern int bob; // don't warn for shadowing.
+}
+
+void test8() {
+ int bob; // expected-warning {{declaration shadows a variable in the global namespace}}
+}
OpenPOWER on IntegriCloud