]> granicus.if.org Git - clang/commitdiff
Don't warn that variables in C++ static member functions shadow fields. Fixes rdar...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 31 Jan 2011 07:04:54 +0000 (07:04 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 31 Jan 2011 07:04:54 +0000 (07:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124581 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-shadow.cpp

index 253f1dcde87ba17b0ef27117676341ba28cf77ea..b2cb96134c0f0057decdca825d89d0ca3cdd34ee 100644 (file)
@@ -3129,6 +3129,12 @@ void Sema::CheckShadow(Scope *S, VarDecl *D, const LookupResult& R) {
   if (!isa<VarDecl>(ShadowedDecl) && !isa<FieldDecl>(ShadowedDecl))
     return;
 
+  // Fields are not shadowed by variables in C++ static methods.
+  if (isa<FieldDecl>(ShadowedDecl))
+    if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewDC))
+      if (MD->isStatic())
+        return;
+
   if (VarDecl *shadowedVar = dyn_cast<VarDecl>(ShadowedDecl))
     if (shadowedVar->isExternC()) {
       // Don't warn for this case:
index 509c34435560beb655cbfb5f84e46b3f51624101..c2ab25c5c26cb70d8459b24d57f9572e551518e9 100644 (file)
@@ -42,3 +42,16 @@ class B : A {
   int data;
   static int field;
 };
+
+// rdar://8900456
+namespace rdar8900456 {
+struct Foo {
+  static void Baz();
+private:
+  int Bar;
+};
+
+void Foo::Baz() {
+  double Bar = 12; // Don't warn.
+}
+}