https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65403
--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> --- For harmonizing how -Wno-X and -Wno-error=X work, it is a bit more convoluted. This mostly works: Index: opts-global.c =================================================================== --- opts-global.c (revision 221118) +++ opts-global.c (working copy) @@ -139,11 +139,11 @@ complain_wrong_lang (const struct cl_dec prevented a diagnostic. Otherwise, we just ignore them. Note that if we do complain, it is only as a warning, not an error; passing the compiler an unrecognized -Wno-* option should never change whether the compilation succeeds or fails. */ -static void +void postpone_unknown_option_warning (const char *opt) { ignored_options.safe_push (opt); } @@ -152,15 +152,20 @@ postpone_unknown_option_warning (const c void print_ignored_options (void) { while (!ignored_options.is_empty ()) { - const char *opt; - - opt = ignored_options.pop (); - warning_at (UNKNOWN_LOCATION, 0, - "unrecognized command line option %qs", opt); + const char * opt = ignored_options.pop (); + if (strcmp (opt, "-Wno-error=") == 0) + { + const char * w_opt = opt + strlen ("-Wno-error="); + warning_at (UNKNOWN_LOCATION, 0, "-Wno-error=%s: no option -W%s", + w_opt, w_opt); + } + else + warning_at (UNKNOWN_LOCATION, 0, + "unrecognized command line option %qs", opt); } } /* Handle an unknown option DECODED, returning true if an error should be given. */ Index: opts.h =================================================================== --- opts.h (revision 221118) +++ opts.h (working copy) @@ -400,6 +400,7 @@ extern void default_options_optimization extern void set_struct_debug_option (struct gcc_options *opts, location_t loc, const char *value); extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg, int *value, unsigned int lang_mask); +extern void postpone_unknown_option_warning (const char *opt); #endif Index: opts.c =================================================================== --- opts.c (revision 221118) +++ opts.c (working copy) @@ -2335,17 +2335,23 @@ enable_warning_as_error (const char *arg location_t loc, diagnostic_context *dc) { char *new_option; int option_index; - new_option = XNEWVEC (char, strlen (arg) + 2); + new_option = XNEWVEC (char, strlen (arg) + strlen ("-Wno-error=") + 1); new_option[0] = 'W'; 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 + strcpy (new_option, "-Wno-error="); + strcat (new_option, arg); + postpone_unknown_option_warning (new_option); + return; } else { const diagnostic_t kind = value ? DK_ERROR : DK_WARNING; with some caveats: * It is a bit too convoluted * In principle enable_warning_as_error() can be called with a loc != UNKNOWN_LOCATION, thus we should record this location for reporting the warning.