diff mbox

[C++] Error on shadowing a parameter by anon union member in the same scope (PR c++/72707)

Message ID 20161220190116.GN21933@tucnak
State New
Headers show

Commit Message

Jakub Jelinek Dec. 20, 2016, 7:01 p.m. UTC
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.


	Jakub

Comments

Jason Merrill Dec. 21, 2016, 10:33 p.m. UTC | #1
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
diff mbox

Patch

--- 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;
+}