[cfe-commits] r130157 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/warn-shadow.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Apr 25 14:39:50 PDT 2011
Author: akirtzidis
Date: Mon Apr 25 16:39:50 2011
New Revision: 130157
URL: http://llvm.org/viewvc/llvm-project?rev=130157&view=rev
Log:
'extern' variables in functions don't shadow externs in global scope. Fixes rdar://8883302, this time for C++ as well.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-shadow.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=130157&r1=130156&r2=130157&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Apr 25 16:39:50 2011
@@ -3664,10 +3664,11 @@
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 @@
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
Modified: cfe/trunk/test/SemaCXX/warn-shadow.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-shadow.cpp?rev=130157&r1=130156&r2=130157&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-shadow.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-shadow.cpp Mon Apr 25 16:39:50 2011
@@ -70,3 +70,14 @@
}
};
}
+
+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}}
+}
More information about the cfe-commits
mailing list