re PR c++/72707 (local anonymous union member hides names in the same scope)
authorJakub Jelinek <jakub@redhat.com>
Wed, 21 Dec 2016 22:49:59 +0000 (23:49 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 21 Dec 2016 22:49:59 +0000 (23:49 +0100)
PR c++/72707
* name-lookup.c (pushdecl_maybe_friend_1): Do check shadowing of
artificial x if it is an anonymous union variable.

* g++.dg/warn/Wshadow-12.C: New test.

From-SVN: r243877

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

index e493fd1fa52be44a68489a8dbbb72359b6ce83b1..925d0b519bf27938e07c4c374da02909ccbda662 100644 (file)
@@ -1,5 +1,9 @@
 2016-12-21  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/72707
+       * name-lookup.c (pushdecl_maybe_friend_1): Do check shadowing of
+       artificial x if it is an anonymous union variable.
+
        PR bootstrap/78817
        * typeck.c (cp_build_function_call_vec): If check_function_arguments
        returns true, set TREE_NO_WARNING on CALL_EXPR.
index a0cadb8d6e74592d1f960a7c4746cfe11fc56c96..223838c3ddf71899b21678150ac60be209f0bb89 100644 (file)
@@ -1111,8 +1111,10 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
                                || TREE_CODE (x) == TYPE_DECL)))
                    /* Don't check for internally generated vars unless
                       it's an implicit typedef (see create_implicit_typedef
-                      in decl.c).  */
-                  && (!DECL_ARTIFICIAL (x) || DECL_IMPLICIT_TYPEDEF_P (x)))
+                      in decl.c) or anonymous union variable.  */
+                  && (!DECL_ARTIFICIAL (x)
+                      || DECL_IMPLICIT_TYPEDEF_P (x)
+                      || (VAR_P (x) && DECL_ANON_UNION_VAR_P (x))))
            {
              bool nowarn = false;
 
index 40f671fee287345f25a175407be95f8c0d7b6c61..3a704c58537bba99e4437473cee4e93c3e6e437d 100644 (file)
@@ -1,3 +1,8 @@
+2016-12-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/72707
+       * g++.dg/warn/Wshadow-12.C: New test.
+
 2016-12-21  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/78580
diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-12.C b/gcc/testsuite/g++.dg/warn/Wshadow-12.C
new file mode 100644 (file)
index 0000000..95dc5be
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/72707
+// { dg-do compile }
+
+void
+foo (double x)
+{
+  union { int x; };    // { dg-error "shadows a parameter" }
+  x = 0;
+}