public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>,
	       Joseph Myers <joseph@codesourcery.com>
Subject: Re: C PATCH to add -Woverride-init-side-effects (PR c/64918)
Date: Thu, 07 May 2015 11:55:00 -0000	[thread overview]
Message-ID: <20150507115505.GD3384@redhat.com> (raw)
In-Reply-To: <20150423223625.GH2813@redhat.com>

Ping.

(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64918#c6 is not addressed in
this patch, it's something to be looked at before closing the PR.)

On Fri, Apr 24, 2015 at 12:36:25AM +0200, Marek Polacek wrote:
> As discussed in the PR, the "initialized field with side-effects overwritten"
> warning is sometimes not so useful, so it probably makes sense to provide an
> option so that users are able to specifically enable/disable it.  Since the
> warning is enabled by default at present, it is enabled by default even with
> this patch, unlike -Woverride-init, which is in -Wextra. 
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2015-04-24  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/64918
> 	* c.opt (Woverride-init-side-effects): New option.
> 
> 	* c-typeck.c (add_pending_init): Use OPT_Woverride_init_side_effects.
> 	(output_init_element): Likewise.
> 
> 	* doc/invoke.texi: Document -Woverride-init-side-effects.
> 
> 	* gcc.dg/Woverride-init-side-effects-1.c: New test.
> 	* gcc.dg/Woverride-init-side-effects-2.c: New test.
> 
> diff --git gcc/c-family/c.opt gcc/c-family/c.opt
> index 983f4a8..50dc8ec 100644
> --- gcc/c-family/c.opt
> +++ gcc/c-family/c.opt
> @@ -709,6 +709,10 @@ Woverride-init
>  C ObjC Var(warn_override_init) Warning EnabledBy(Wextra)
>  Warn about overriding initializers without side effects
>  
> +Woverride-init-side-effects
> +C ObjC Var(warn_override_init_side_effects) Init(1) Warning
> +Warn about overriding initializers with side effects
> +
>  Wpacked-bitfield-compat
>  C ObjC C++ ObjC++ Var(warn_packed_bitfield_compat) Init(-1) Warning
>  Warn about packed bit-fields whose offset changed in GCC 4.4
> diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
> index 91735b5..635b568 100644
> --- gcc/c/c-typeck.c
> +++ gcc/c/c-typeck.c
> @@ -7978,7 +7978,7 @@ add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
>  	      if (!implicit)
>  		{
>  		  if (TREE_SIDE_EFFECTS (p->value))
> -		    warning_init (loc, 0,
> +		    warning_init (loc, OPT_Woverride_init_side_effects,
>  				  "initialized field with side-effects "
>  				  "overwritten");
>  		  else if (warn_override_init)
> @@ -8008,7 +8008,7 @@ add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
>  	      if (!implicit)
>  		{
>  		  if (TREE_SIDE_EFFECTS (p->value))
> -		    warning_init (loc, 0,
> +		    warning_init (loc, OPT_Woverride_init_side_effects,
>  				  "initialized field with side-effects "
>  				  "overwritten");
>  		  else if (warn_override_init)
> @@ -8540,7 +8540,7 @@ output_init_element (location_t loc, tree value, tree origtype,
>        if (!implicit)
>  	{
>  	  if (TREE_SIDE_EFFECTS (constructor_elements->last ().value))
> -	    warning_init (loc, 0,
> +	    warning_init (loc, OPT_Woverride_init_side_effects,
>  			  "initialized field with side-effects overwritten");
>  	  else if (warn_override_init)
>  	    warning_init (loc, OPT_Woverride_init,
> diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi
> index a939ff7..ff2ff24 100644
> --- gcc/doc/invoke.texi
> +++ gcc/doc/invoke.texi
> @@ -266,6 +266,7 @@ Objective-C and Objective-C++ Dialects}.
>  -Wmissing-field-initializers -Wmissing-include-dirs @gol
>  -Wno-multichar  -Wnonnull  -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]} @gol
>  -Wodr  -Wno-overflow  -Wopenmp-simd @gol
> +-Woverride-init-side-effects @gol
>  -Woverlength-strings  -Wpacked  -Wpacked-bitfield-compat  -Wpadded @gol
>  -Wparentheses  -Wpedantic-ms-format -Wno-pedantic-ms-format @gol
>  -Wpointer-arith  -Wno-pointer-to-int-cast @gol
> @@ -5177,6 +5178,13 @@ This warning is included in @option{-Wextra}.  To get other
>  @option{-Wextra} warnings without this one, use @option{-Wextra
>  -Wno-override-init}.
>  
> +@item -Woverride-init-side-effects @r{(C and Objective-C only)}
> +@opindex Woverride-init-side-effects
> +@opindex Wno-override-init-side-effects
> +Warn if an initialized field with side effects is overridden when
> +using designated initializers (@pxref{Designated Inits, , Designated
> +Initializers}).  This warning is enabled by default.
> +
>  @item -Wpacked
>  @opindex Wpacked
>  @opindex Wno-packed
> diff --git gcc/testsuite/gcc.dg/Woverride-init-side-effects-1.c gcc/testsuite/gcc.dg/Woverride-init-side-effects-1.c
> index e69de29..50f198d 100644
> --- gcc/testsuite/gcc.dg/Woverride-init-side-effects-1.c
> +++ gcc/testsuite/gcc.dg/Woverride-init-side-effects-1.c
> @@ -0,0 +1,25 @@
> +/* PR c/64918 */
> +/* { dg-do compile } */
> +/* { dg-options "" } */
> +
> +struct S { int m, n; };
> +union U { short s; long int l; };
> +
> +void
> +foo (int i)
> +{
> +  int a[] = {
> +    [0] = ++i,
> +    [1] = i,
> +    [0] = 42	/* { dg-warning "initialized field with side-effects overwritten" } */
> +  };
> +  struct S s = {
> +    .n = ++i,
> +    .m = i,
> +    .n = i	/* { dg-warning "initialized field with side-effects overwritten" } */
> +  };
> +  union U u = {
> +    .s = i--,
> +    .l = 42	/* { dg-warning "initialized field with side-effects overwritten" } */
> +  };
> +}
> diff --git gcc/testsuite/gcc.dg/Woverride-init-side-effects-2.c gcc/testsuite/gcc.dg/Woverride-init-side-effects-2.c
> index e69de29..a64e96a 100644
> --- gcc/testsuite/gcc.dg/Woverride-init-side-effects-2.c
> +++ gcc/testsuite/gcc.dg/Woverride-init-side-effects-2.c
> @@ -0,0 +1,25 @@
> +/* PR c/64918 */
> +/* { dg-do compile } */
> +/* { dg-options "-Wno-override-init-side-effects" } */
> +
> +struct S { int m, n; };
> +union U { short s; long int l; };
> +
> +void
> +foo (int i)
> +{
> +  int a[] = {
> +    [0] = ++i,
> +    [1] = i,
> +    [0] = 42
> +  };
> +  struct S s = {
> +    .n = ++i,
> +    .m = i,
> +    .n = i
> +  };
> +  union U u = {
> +    .s = i--,
> +    .l = 42
> +  };
> +}
> 
> 	Marek

	Marek

  reply	other threads:[~2015-05-07 11:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-23 22:36 Marek Polacek
2015-05-07 11:55 ` Marek Polacek [this message]
2015-05-07 20:35 ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150507115505.GD3384@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).