diff mbox

PR c++/33255 - Support -Wunused-local-typedefs warning

Message ID m3obyurc7b.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli Sept. 8, 2011, 8:50 p.m. UTC
Jason Merrill <jason@redhat.com> writes:

> I think -Wunused and -Wall should imply -Wunused-local-typedefs unless
> the user specifies -Wno-unused-local-typedefs.

Dodji Seketeli <dodji@redhat.com> writes:

> I actually first tried this (actually adding it to -Wall -extra and
> -Wunused) and found out the following issue.
> 
> A typedef can be defined in a macro in a system header, be expanded in
> a function and not be used by the function.  In this case we shouldn't
> warn, but PR preprocessor/7263 makes us warn nonetheless.  There are
> many spots of that kind in the libstdc++ test suite.
> 

Jason Merrill <jason@redhat.com> writes:

> Does your set of linemap patches fix the issue?  In that case, we can
> add it when those go in.  Speaking of which, sorry I haven't found the
> time to review them yet.

So, in prevision of when the patch for PR preprocessor/7263 goes in, I
am proposing this patchlet that turns on -Wunused-local-typedefs
whenever -Wunused (and so -Wall) is turned on.

I have tested it on a synthetic tree made of my current patch series for
PR preprocessor/7263, and trunk that contains -Wunused-local-typedefs
support.

Is this be OK for trunk when PR preprocessor/7263 gets in, assuming it
passes bootstrap and tests on trunk at that moment?

Thanks.


    Enable -Wunused-local-typedefs when -Wall or -Wunused
    
    gcc/
    
    	* opts.c (finish_options): Activate -Wunused-local-typedefs if
    	-Wunused is activated.
    	* doc/invoke.texi: Update blurb of -Wunused-local-typedefs.

Comments

Jason Merrill Sept. 8, 2011, 8:59 p.m. UTC | #1
On 09/08/2011 04:50 PM, Dodji Seketeli wrote:
> Is this be OK for trunk when PR preprocessor/7263 gets in, assuming it
> passes bootstrap and tests on trunk at that moment?

Yes, except...

> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -3505,6 +3505,7 @@ To suppress this warning use the @samp{unused} attribute
>   @item -Wunused-local-typedefs @r{(C, Objective-C, C++ and Objective-C++ only)}
>   @opindex Wunused-local-typedefs
>   Warn when a typedef locally defined in a function is not used.
> +This warning is enabled by @option{-Wall}.

Don't you want to say "This warning is also enabled by 
@option{-Wunused}, which is enabled by @option{-Wall}."?

Jason
Dodji Seketeli Sept. 8, 2011, 9:54 p.m. UTC | #2
Jason Merrill <jason@redhat.com> writes:

> On 09/08/2011 04:50 PM, Dodji Seketeli wrote:
>> Is this be OK for trunk when PR preprocessor/7263 gets in, assuming it
>> passes bootstrap and tests on trunk at that moment?
>
> Yes, except...
>
>> --- a/gcc/doc/invoke.texi
>> +++ b/gcc/doc/invoke.texi
>> @@ -3505,6 +3505,7 @@ To suppress this warning use the @samp{unused} attribute
>>   @item -Wunused-local-typedefs @r{(C, Objective-C, C++ and Objective-C++ only)}
>>   @opindex Wunused-local-typedefs
>>   Warn when a typedef locally defined in a function is not used.
>> +This warning is enabled by @option{-Wall}.
>
> Don't you want to say "This warning is also enabled by
> @option{-Wunused}, which is enabled by @option{-Wall}."?

For the sake of consistency, I followed the pattern used for the other
-Wunused-* options in that same file.

I thought I didn't have to mention that -Wunused triggers
-Wunused-local-typedefs because a bit below this, the text for -Wunused
reads:

    All the above @option{-Wunused} options combined.

And before that, each relevant -Wunused-* option is said to be triggered
by -Wall, as I did.

I would also find your phrasing more logical, if it wasn't for the
consistency constraint.
Jason Merrill Sept. 9, 2011, 5:14 a.m. UTC | #3
On 09/08/2011 05:54 PM, Dodji Seketeli wrote:
> Jason Merrill<jason@redhat.com>  writes:
>
>> Don't you want to say "This warning is also enabled by
>> @option{-Wunused}, which is enabled by @option{-Wall}."?
>
> For the sake of consistency, I followed the pattern used for the other
> -Wunused-* options in that same file.

OK.

Jason
diff mbox

Patch

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3aa9611..5f4afe3 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -3505,6 +3505,7 @@  To suppress this warning use the @samp{unused} attribute
 @item -Wunused-local-typedefs @r{(C, Objective-C, C++ and Objective-C++ only)}
 @opindex Wunused-local-typedefs
 Warn when a typedef locally defined in a function is not used.
+This warning is enabled by @option{-Wall}.
 
 @item -Wunused-parameter
 @opindex Wunused-parameter
diff --git a/gcc/opts.c b/gcc/opts.c
index 5d5bcb9..ebb99d0 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -830,6 +830,10 @@  finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
   if (opts->x_warn_unused_value == -1)
     opts->x_warn_unused_value = opts->x_warn_unused;
 
+  /* Wunused-local-typedefs is enabled by -Wunused or -Wall.  */
+  if (opts->x_warn_unused_local_typedefs == -1)
+    opts->x_warn_unused_local_typedefs = opts->x_warn_unused;
+
   /* This replaces set_Wextra.  */
   if (opts->x_warn_uninitialized == -1)
     opts->x_warn_uninitialized = opts->x_extra_warnings;