This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Error on shadowing a parameter by anon union member in the same scope (PR c++/72707)
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 21 Dec 2016 17:33:59 -0500
- Subject: Re: [C++ PATCH] Error on shadowing a parameter by anon union member in the same scope (PR c++/72707)
- Authentication-results: sourceware.org; auth=none
- References: <20161220190116.GN21933@tucnak>
OK.
On Tue, Dec 20, 2016 at 2:01 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> 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 <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.
>
> * 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