From b5f8e89ed7dc34e6850430315730b7601032bd89 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 21 Dec 2016 23:49:59 +0100 Subject: [PATCH] re PR c++/72707 (local anonymous union member hides names in the same scope) 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 | 4 ++++ gcc/cp/name-lookup.c | 6 ++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/Wshadow-12.C | 9 +++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-12.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e493fd1fa52..925d0b519bf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2016-12-21 Jakub Jelinek + 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. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index a0cadb8d6e7..223838c3ddf 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 40f671fee28..3a704c58537 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-12-21 Jakub Jelinek + + PR c++/72707 + * g++.dg/warn/Wshadow-12.C: New test. + 2016-12-21 Vladimir Makarov 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 index 00000000000..95dc5beb96c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-12.C @@ -0,0 +1,9 @@ +// PR c++/72707 +// { dg-do compile } + +void +foo (double x) +{ + union { int x; }; // { dg-error "shadows a parameter" } + x = 0; +} -- 2.30.2