Author: akirtzidis Date: Tue Feb 8 12:21:25 2011 New Revision: 125097 URL: http://llvm.org/viewvc/llvm-project?rev=125097&view=rev Log: In Sema::CheckShadow, get the DeclContext from the variable that we are checking instead from the Scope; Inner scopes in bodies don't have DeclContexts associated with them.
Fixes http://llvm.org/PR9160 & rdar://problem/8966163. 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=125097&r1=125096&r2=125097&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Feb 8 12:21:25 2011 @@ -3121,10 +3121,9 @@ Diagnostic::Ignored) return; - // Don't diagnose declarations at file scope. The scope might not - // have a DeclContext if (e.g.) we're parsing a function prototype. - DeclContext *NewDC = static_cast<DeclContext*>(S->getEntity()); - if (NewDC && NewDC->isFileContext()) + // Don't diagnose declarations at file scope. + DeclContext *NewDC = D->getDeclContext(); + if (NewDC->isFileContext()) return; // Only diagnose if we're shadowing an unambiguous field or variable. Modified: cfe/trunk/test/SemaCXX/warn-shadow.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-shadow.cpp?rev=125097&r1=125096&r2=125097&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/warn-shadow.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-shadow.cpp Tue Feb 8 12:21:25 2011 @@ -55,3 +55,18 @@ double Bar = 12; // Don't warn. } } + +// http://llvm.org/PR9160 +namespace PR9160 { +struct V { + V(int); +}; +struct S { + V v; + static void m() { + if (1) { + V v(0); + } + } +}; +} _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
