Hi! DECL_ANON_UNION_VAR_P vars are DECL_ARTIFICIAL, but we still to diagnose them if they shadow something. The DECL_ARTIFICIAL (x) check has been missing in older gcc releases, so we diagnosed that properly.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-12-20 Jakub Jelinek <ja...@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. * g++.dg/warn/Wshadow-12.C: New test. --- gcc/cp/name-lookup.c.jj 2016-11-30 08:57:21.000000000 +0100 +++ gcc/cp/name-lookup.c 2016-12-20 14:42:35.482232062 +0100 @@ -1111,8 +1111,10 @@ pushdecl_maybe_friend_1 (tree x, bool is || 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; --- gcc/testsuite/g++.dg/warn/Wshadow-12.C.jj 2016-12-20 14:41:28.083114644 +0100 +++ gcc/testsuite/g++.dg/warn/Wshadow-12.C 2016-12-20 14:40:19.000000000 +0100 @@ -0,0 +1,9 @@ +// PR c++/72707 +// { dg-do compile } + +void +foo (double x) +{ + union { int x; }; // { dg-error "shadows a parameter" } + x = 0; +} Jakub