re PR c++/68374 (G++ -Wshadow doesn't warn about static member shadowing)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 2 May 2018 18:15:56 +0000 (18:15 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 2 May 2018 18:15:56 +0000 (18:15 +0000)
/cp
2018-05-02  Paolo Carlini  <paolo.carlini@oracle.com>
    Jason Merrill  <jason@redhat.com>

PR c++/68374
* name-lookup.c (check_local_shadow): Don't handle static old
declarations in the block handling locals shadowing locals.

/testsuite
2018-05-02  Paolo Carlini  <paolo.carlini@oracle.com>
    Jason Merrill  <jason@redhat.com>

PR c++/68374
* g++.dg/warn/Wshadow-13.C: New.
* g++.dg/warn/Wshadow-14.C: Likewise.

Co-Authored-By: Jason Merrill <jason@redhat.com>
From-SVN: r259853

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wshadow-13.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wshadow-14.C [new file with mode: 0644]

index 604e704fb2c394ef0fad0f7a987b237c90b39d3a..fadcea80a94f865dc03a565b1098de71fc1fcd9e 100644 (file)
@@ -1,3 +1,10 @@
+2018-05-02  Paolo Carlini  <paolo.carlini@oracle.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/68374
+       * name-lookup.c (check_local_shadow): Don't handle static old
+       declarations in the block handling locals shadowing locals.
+
 2018-05-01  Jason Merrill  <jason@redhat.com>
 
        PR c++/85587 - error with scoped enum in template.
index 64c7b6f006e7d8796663cf6d47de11b58972155b..08cabd68a848d8af65e52bb4190829ffa50e9753 100644 (file)
@@ -2642,6 +2642,7 @@ check_local_shadow (tree decl)
          || (TREE_CODE (old) == TYPE_DECL
              && (!DECL_ARTIFICIAL (old)
                  || TREE_CODE (decl) == TYPE_DECL)))
+      && DECL_FUNCTION_SCOPE_P (old)
       && (!DECL_ARTIFICIAL (decl)
          || DECL_IMPLICIT_TYPEDEF_P (decl)
          || (VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))))
index 9c290eb1e68f70538617ba71295d246adfca131a..6ddb945c70e60c92eab1bd260d5784547855e20a 100644 (file)
@@ -1,3 +1,10 @@
+2018-05-02  Paolo Carlini  <paolo.carlini@oracle.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/68374
+       * g++.dg/warn/Wshadow-13.C: New.
+       * g++.dg/warn/Wshadow-14.C: Likewise.
+
 2018-05-02  Tom de Vries  <tom@codesourcery.com>
 
        PR libgomp/82428
diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-13.C b/gcc/testsuite/g++.dg/warn/Wshadow-13.C
new file mode 100644 (file)
index 0000000..d75560c
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/68374
+// { dg-options "-Wshadow" }
+
+class f {
+  static int mVar;  // { dg-message "shadowed declaration" }
+  int g(int x) { int mVar=3; return x+mVar; }  // { dg-warning "shadows a member of 'f'" }
+};
+int f::mVar = 1;
diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-14.C b/gcc/testsuite/g++.dg/warn/Wshadow-14.C
new file mode 100644 (file)
index 0000000..e0e3d02
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/68374
+// { dg-options "-Wshadow" }
+
+void foo ()
+{
+  static int i;  // { dg-message "shadowed declaration" }
+  {
+    int i;  // { dg-warning "shadows a previous local" }
+  }
+}