]> granicus.if.org Git - clang/commitdiff
'extern' variables in functions don't shadow externs in global scope. Fixes rdar...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 25 Apr 2011 21:39:50 +0000 (21:39 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 25 Apr 2011 21:39:50 +0000 (21:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130157 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-shadow.cpp

index d07bd4b72d39aedf70e9afe7c9105a09638d4d25..200f8ce03792e7c94e393e43ee6a89633c62c464 100644 (file)
@@ -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
index 3bf9af414db079be07c417ec8967f931e558cd94..68e9467a937b1472876f33ee9c6800ab916b2c10 100644 (file)
@@ -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}}
+}