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.
llvm-svn: 125097
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a519096..ac8e042 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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.
diff --git a/clang/test/SemaCXX/warn-shadow.cpp b/clang/test/SemaCXX/warn-shadow.cpp
index c2ab25c..3bf9af4 100644
--- a/clang/test/SemaCXX/warn-shadow.cpp
+++ b/clang/test/SemaCXX/warn-shadow.cpp
@@ -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);
+ }
+ }
+};
+}