diff mbox series

[1/2] PR c/65403 - Ignore -Wno-error=<some-future-warning>

Message ID 20190319024657.11618-2-alexhenrie24@gmail.com
State New
Headers show
Series Future warnings not treated as errors | expand

Commit Message

Alex Henrie March 19, 2019, 2:46 a.m. UTC
From: Manuel López-Ibáñez <manu@gcc.gnu.org>

* opts.c: Ignore -Wno-error=<some-future-warning> except if there are
other diagnostics.
---
 gcc/opts-common.c |  2 ++
 gcc/opts-global.c | 10 +++++++---
 gcc/opts.c        |  5 ++++-
 gcc/opts.h        |  2 ++
 4 files changed, 15 insertions(+), 4 deletions(-)

Comments

Martin Sebor March 19, 2019, 5:26 p.m. UTC | #1
On 3/18/19 8:46 PM, Alex Henrie wrote:
> From: Manuel López-Ibáñez <manu@gcc.gnu.org>
> 
> * opts.c: Ignore -Wno-error=<some-future-warning> except if there are
> other diagnostics.
> ---
>   gcc/opts-common.c |  2 ++
>   gcc/opts-global.c | 10 +++++++---
>   gcc/opts.c        |  5 ++++-
>   gcc/opts.h        |  2 ++
>   4 files changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/gcc/opts-common.c b/gcc/opts-common.c
> index edbb3ac9b6d..36e06e2372a 100644
> --- a/gcc/opts-common.c
> +++ b/gcc/opts-common.c
> @@ -26,6 +26,8 @@ along with GCC; see the file COPYING3.  If not see
>   #include "diagnostic.h"
>   #include "spellcheck.h"
>   
> +vec<const char *> ignored_wnoerror_options;
> +
>   static void prune_options (struct cl_decoded_option **, unsigned int *);
>   
>   /* An option that is undocumented, that takes a joined argument, and
> diff --git a/gcc/opts-global.c b/gcc/opts-global.c
> index a5e9ef0237a..0b2550a4855 100644
> --- a/gcc/opts-global.c
> +++ b/gcc/opts-global.c
> @@ -132,12 +132,16 @@ print_ignored_options (void)
>   {
>     while (!ignored_options.is_empty ())
>       {
> -      const char *opt;
> -
> -      opt = ignored_options.pop ();
> +      const char * opt = ignored_options.pop ();
>         warning_at (UNKNOWN_LOCATION, 0,
>   		  "unrecognized command line option %qs", opt);
>       }
> +  while (!ignored_wnoerror_options.is_empty ())
> +    {
> +      const char * opt = ignored_wnoerror_options.pop ();
> +      warning_at (UNKNOWN_LOCATION, 0,
> +		  "-Wno-error=%s: no option -W%s", opt, opt);

Please remember to quote the command line options in the message
(same as in the error below):

> +    }
>   }
>   
>   /* Handle an unknown option DECODED, returning true if an error should
> diff --git a/gcc/opts.c b/gcc/opts.c
> index 3161e0b6753..4fa79306e30 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -3079,7 +3079,10 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
>     strcpy (new_option + 1, arg);
>     option_index = find_opt (new_option, lang_mask);
>     if (option_index == OPT_SPECIAL_unknown)
> -    error_at (loc, "%<-Werror=%s%>: no option -%s", arg, new_option);
> +    if (value)
> +      error_at (loc, "%<-Werror=%s%>: no option -%s", arg, new_option);
                          ^^^^^^^^^^^^^^

Like that.

Thanks
Martin


> +    else
> +      ignored_wnoerror_options.safe_push (arg);
>     else if (!(cl_options[option_index].flags & CL_WARNING))
>       error_at (loc, "%<-Werror=%s%>: -%s is not an option that controls "
>   	      "warnings", arg, new_option);
> diff --git a/gcc/opts.h b/gcc/opts.h
> index f14d9bcb896..b18504e0bc3 100644
> --- a/gcc/opts.h
> +++ b/gcc/opts.h
> @@ -456,4 +456,6 @@ extern bool parse_and_check_align_values (const char *flag,
>   					  bool report_error,
>   					  location_t loc);
>   
> +extern vec<const char *> ignored_wnoerror_options;
> +
>   #endif
>
Alex Henrie March 20, 2019, 4:07 a.m. UTC | #2
On Tue, Mar 19, 2019 at 11:26 AM Martin Sebor <msebor@gmail.com> wrote:
>
> Please remember to quote the command line options in the message
> (same as in the error below):

I'll send a new version. Thanks for the feedback!

-Alex
Jeff Law June 19, 2019, 5:52 p.m. UTC | #3
On 3/18/19 8:46 PM, Alex Henrie wrote:
> From: Manuel López-Ibáñez <manu@gcc.gnu.org>
> 
> * opts.c: Ignore -Wno-error=<some-future-warning> except if there are
> other diagnostics.
That's not a complete ChangeLog entry.  Each file/function changed
should be mentioned.  Something like this:

	* opts-common.c (ignored_wnoerror_options): New global variable.
	* opts-global.c (print_ignored_options): Ignore
	-Wno-error=<some-future-warning> except if there are other
	diagnostics.
	* opts.c (enable_warning_as_error): Record ignored -Wno-error
	options.
	opts.h (ignored_wnoerror_options): Declare.

> diff --git a/gcc/opts.c b/gcc/opts.c
> index 3161e0b6753..4fa79306e30 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -3079,7 +3079,10 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
>    strcpy (new_option + 1, arg);
>    option_index = find_opt (new_option, lang_mask);
>    if (option_index == OPT_SPECIAL_unknown)
> -    error_at (loc, "%<-Werror=%s%>: no option -%s", arg, new_option);
> +    if (value)
> +      error_at (loc, "%<-Werror=%s%>: no option -%s", arg, new_option);
> +    else
> +      ignored_wnoerror_options.safe_push (arg);
>    else if (!(cl_options[option_index].flags & CL_WARNING))
>      error_at (loc, "%<-Werror=%s%>: -%s is not an option that controls "
>  	      "warnings", arg, new_option);
This hunk is my only concern with the patch.  In particular how is this
going to interact with the hints/suggestions we emit when we see an
unknown option?

The code on the trunk looks like this now:

>   if (option_index == OPT_SPECIAL_unknown)
>     {
>       option_proposer op;
>       const char *hint = op.suggest_option (new_option);
>       if (hint)
>         error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>;"
>                   " did you mean %<-%s%>?", value ? "" : "no-",
>                   arg, new_option, hint);
>       else
>         error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>",
>                   value ? "" : "no-", arg, new_option);
>     }
If HINT is set, do we still want to potentially push the argument onto
the ignored_wnoerror_options list?  My inclination is yes since the hint
is just that, a fuzzily matched hint.  That hint may be appropriate
(user typo'd or somesuch) or it may be totally offbase (user was trying
to turn off some future warning.

I'm open to other opinions here.

jeff
Alex Henrie June 26, 2019, 2:04 a.m. UTC | #4
On Wed, Jun 19, 2019 at 11:52 AM Jeff Law <law@redhat.com> wrote:
>
> On 3/18/19 8:46 PM, Alex Henrie wrote:
> > From: Manuel López-Ibáñez <manu@gcc.gnu.org>
> >
> > * opts.c: Ignore -Wno-error=<some-future-warning> except if there are
> > other diagnostics.
> That's not a complete ChangeLog entry.  Each file/function changed
> should be mentioned.  Something like this:
>
>         * opts-common.c (ignored_wnoerror_options): New global variable.
>         * opts-global.c (print_ignored_options): Ignore
>         -Wno-error=<some-future-warning> except if there are other
>         diagnostics.
>         * opts.c (enable_warning_as_error): Record ignored -Wno-error
>         options.
>         opts.h (ignored_wnoerror_options): Declare.

Thanks!

> If HINT is set, do we still want to potentially push the argument onto
> the ignored_wnoerror_options list?  My inclination is yes since the hint
> is just that, a fuzzily matched hint.  That hint may be appropriate
> (user typo'd or somesuch) or it may be totally offbase (user was trying
> to turn off some future warning.

I don't think we need to support hints in the case of
-Wno-error=<some-unknown-warning> because we don't support hints for
-Wno-<some-unknown-warning> and as you pointed out, hints are less
likely to be helpful here because the warning may be perfectly valid
in a newer version of GCC.

I'll send rebased patches later tonight. Thanks for the feedback!

-Alex
diff mbox series

Patch

diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index edbb3ac9b6d..36e06e2372a 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -26,6 +26,8 @@  along with GCC; see the file COPYING3.  If not see
 #include "diagnostic.h"
 #include "spellcheck.h"
 
+vec<const char *> ignored_wnoerror_options;
+
 static void prune_options (struct cl_decoded_option **, unsigned int *);
 
 /* An option that is undocumented, that takes a joined argument, and
diff --git a/gcc/opts-global.c b/gcc/opts-global.c
index a5e9ef0237a..0b2550a4855 100644
--- a/gcc/opts-global.c
+++ b/gcc/opts-global.c
@@ -132,12 +132,16 @@  print_ignored_options (void)
 {
   while (!ignored_options.is_empty ())
     {
-      const char *opt;
-
-      opt = ignored_options.pop ();
+      const char * opt = ignored_options.pop ();
       warning_at (UNKNOWN_LOCATION, 0,
 		  "unrecognized command line option %qs", opt);
     }
+  while (!ignored_wnoerror_options.is_empty ())
+    {
+      const char * opt = ignored_wnoerror_options.pop ();
+      warning_at (UNKNOWN_LOCATION, 0,
+		  "-Wno-error=%s: no option -W%s", opt, opt);
+    }
 }
 
 /* Handle an unknown option DECODED, returning true if an error should
diff --git a/gcc/opts.c b/gcc/opts.c
index 3161e0b6753..4fa79306e30 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -3079,7 +3079,10 @@  enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
   strcpy (new_option + 1, arg);
   option_index = find_opt (new_option, lang_mask);
   if (option_index == OPT_SPECIAL_unknown)
-    error_at (loc, "%<-Werror=%s%>: no option -%s", arg, new_option);
+    if (value)
+      error_at (loc, "%<-Werror=%s%>: no option -%s", arg, new_option);
+    else
+      ignored_wnoerror_options.safe_push (arg);
   else if (!(cl_options[option_index].flags & CL_WARNING))
     error_at (loc, "%<-Werror=%s%>: -%s is not an option that controls "
 	      "warnings", arg, new_option);
diff --git a/gcc/opts.h b/gcc/opts.h
index f14d9bcb896..b18504e0bc3 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -456,4 +456,6 @@  extern bool parse_and_check_align_values (const char *flag,
 					  bool report_error,
 					  location_t loc);
 
+extern vec<const char *> ignored_wnoerror_options;
+
 #endif