]> granicus.if.org Git - clang/commitdiff
In Sema::CheckShadow, get the DeclContext from the variable that we are checking
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 8 Feb 2011 18:21:25 +0000 (18:21 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 8 Feb 2011 18:21:25 +0000 (18:21 +0000)
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
test/SemaCXX/warn-shadow.cpp

index a5190961b5304305759e8bc95a99bd44d755fb44..ac8e042545892df1631f6c7b70148299a340af58 100644 (file)
@@ -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<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.
index c2ab25c5c26cb70d8459b24d57f9572e551518e9..3bf9af414db079be07c417ec8967f931e558cd94 100644 (file)
@@ -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);
+    }
+  }
+};
+}