Hi,

this issue is by and large fixed in trunk, thus I wanted to resolve it as such, marking it as fixed for 8.1.0. However the text of the warning is misleading / wrong:

    declaration of ‘mVar’ shadows a previous local

where in fact the shadowed declaration isn't local, is a static data member of the class. It seems to me that we should simply not handle such static old decls in the conditional block handling locals shadowing other locals, thus handle those below, together with other non-static member declarations. Tested x86-64-linux.

Thanks, Paolo.

///////////////////

/cp
2018-04-23  Paolo Carlini  <paolo.carl...@oracle.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-04-23  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/68374
        * g++.dg/warn/Wshadow-13.C: New.
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c    (revision 259571)
+++ cp/name-lookup.c    (working copy)
@@ -2638,6 +2638,7 @@ check_local_shadow (tree decl)
          || (TREE_CODE (old) == TYPE_DECL
              && (!DECL_ARTIFICIAL (old)
                  || TREE_CODE (decl) == TYPE_DECL)))
+      && !TREE_STATIC (old)
       && (!DECL_ARTIFICIAL (decl)
          || DECL_IMPLICIT_TYPEDEF_P (decl)
          || (VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))))
Index: testsuite/g++.dg/warn/Wshadow-13.C
===================================================================
--- testsuite/g++.dg/warn/Wshadow-13.C  (nonexistent)
+++ testsuite/g++.dg/warn/Wshadow-13.C  (working copy)
@@ -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;

Reply via email to