From 651f86fb6b0f1a251c65a9be6d3fa83e67d5988d Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 8 Feb 2011 18:21:25 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125097 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 7 +++---- test/SemaCXX/warn-shadow.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a5190961b5..ac8e042545 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3121,10 +3121,9 @@ void Sema::CheckShadow(Scope *S, VarDecl *D, const LookupResult& R) { 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(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. diff --git a/test/SemaCXX/warn-shadow.cpp b/test/SemaCXX/warn-shadow.cpp index c2ab25c5c2..3bf9af414d 100644 --- a/test/SemaCXX/warn-shadow.cpp +++ b/test/SemaCXX/warn-shadow.cpp @@ -55,3 +55,18 @@ void Foo::Baz() { 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); + } + } +}; +}