From: Manuel López-Ibáñez <[email protected]>
* 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.
* gcc.dg/Werror-13.c: Don't expect hints for
-Wno-error=<some-future-warning>.
---
gcc/opts-common.c | 2 ++
gcc/opts-global.c | 10 +++++++---
gcc/opts.c | 21 +++++++++++++--------
gcc/opts.h | 2 ++
gcc/testsuite/gcc.dg/Werror-13.c | 2 +-
5 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 660dfe63858..8ceb8461f97 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 bf4db775928..1d5d4e69dfc 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 b38bfb15a56..f31b6aa877e 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -3095,15 +3095,20 @@ enable_warning_as_error (const char *arg, int value,
unsigned int lang_mask,
option_index = find_opt (new_option, lang_mask);
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);
+ if (value)
+ {
+ 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);
+ }
else
- error_at (loc, "%<-W%serror=%s%>: no option %<-%s%>",
- value ? "" : "no-", arg, new_option);
+ 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 "
diff --git a/gcc/opts.h b/gcc/opts.h
index e5723a946f7..f553e8d00f0 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -460,4 +460,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
diff --git a/gcc/testsuite/gcc.dg/Werror-13.c b/gcc/testsuite/gcc.dg/Werror-13.c
index 3a02b7ea2b5..7c2bf6836ed 100644
--- a/gcc/testsuite/gcc.dg/Werror-13.c
+++ b/gcc/testsuite/gcc.dg/Werror-13.c
@@ -5,6 +5,6 @@
/* { dg-error "'-Werror' is not an option that controls warnings" "" { target
*-*-* } 0 } */
/* { dg-error "'-Wfatal-errors' is not an option that controls warnings" "" {
target *-*-* } 0 } */
/* { dg-error "'-Werror=vla2': no option '-Wvla2'; did you mean '-Wvla." "" {
target *-*-* } 0 } */
-/* { dg-error "'-Wno-error=misleading-indentation2': no option
'-Wmisleading-indentation2'; did you mean '-Wmisleading-indentation'" "" {
target *-*-* } 0 } */
+/* { dg-warning "'-Wno-error=misleading-indentation2': no option
'-Wmisleading-indentation2'" "" { target *-*-* } 0 } */
int i;
--
2.22.0