'extern' variables in functions don't shadow externs in global scope. Fixes rdar://8883302.

llvm-svn: 124578
This commit is contained in:
Argyrios Kyrtzidis 2011-01-31 07:04:41 +00:00
parent 77fd99f8ae
commit f41860c882
2 changed files with 19 additions and 0 deletions

View 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.

View 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.
}