[cfe-commits] r124578 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/warn-shadow.c
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Jan 30 23:04:41 PST 2011
Author: akirtzidis
Date: Mon Jan 31 01:04:41 2011
New Revision: 124578
URL: http://llvm.org/viewvc/llvm-project?rev=124578&view=rev
Log:
'extern' variables in functions don't shadow externs in global scope. Fixes rdar://8883302.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/warn-shadow.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=124578&r1=124577&r2=124578&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 31 01:04:41 2011
@@ -3117,6 +3117,19 @@
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.
Modified: cfe/trunk/test/Sema/warn-shadow.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-shadow.c?rev=124578&r1=124577&r2=124578&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-shadow.c (original)
+++ cfe/trunk/test/Sema/warn-shadow.c Mon Jan 31 01:04:41 2011
@@ -48,3 +48,9 @@
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.
+}
More information about the cfe-commits
mailing list