]> 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, 31 Jan 2011 07:04:41 +0000 (07:04 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 31 Jan 2011 07:04:41 +0000 (07:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124578 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 1c487b8113ad7b74311f03bace9ee98396cd3e81..bcc67b2e9a98f236d4176d8ba687fc4b7fc72a2b 100644 (file)
@@ -3117,6 +3117,19 @@ void Sema::CheckShadow(Scope *S, VarDecl *D, const LookupResult& R) {
 
   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())
+        return;
+
   // Only warn about certain kinds of shadowing for class members.
   if (NewDC && NewDC->isRecord()) {
     // In particular, don't warn about shadowing non-class members.
index a112210c96935411896ed40771cf704e7b39352c..c77bb0c450b43b38128c3424b60970cecf736b52 100644 (file)
@@ -48,3 +48,9 @@ void test4(int i) { // expected-warning {{declaration shadows a variable in the
 void test5(int i);
 void test6(void (*f)(int i)) {}
 void test7(void *context, void (*callback)(void *context)) {}
+
+// rdar://8883302
+extern int bob;
+void rdar8883302() {
+  extern int bob; // don't warn for shadowing.
+}