* [C++ PATCH] Error on shadowing a parameter by anon union member in the same scope (PR c++/72707)
@ 2016-12-20 19:09 Jakub Jelinek
2016-12-21 22:34 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-12-20 19:09 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Error on shadowing a parameter by anon union member in the same scope (PR c++/72707)
2016-12-20 19:09 [C++ PATCH] Error on shadowing a parameter by anon union member in the same scope (PR c++/72707) Jakub Jelinek
@ 2016-12-21 22:34 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-12-21 22:34 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches List
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-12-21 22:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-20 19:09 [C++ PATCH] Error on shadowing a parameter by anon union member in the same scope (PR c++/72707) Jakub Jelinek
2016-12-21 22:34 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).