https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111918
Lewis Hyatt <lhyatt at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lhyatt at gcc dot gnu.org Status|UNCONFIRMED |NEW Last reconfirmed| |2023-11-09 Ever confirmed|0 |1 --- Comment #3 from Lewis Hyatt <lhyatt at gcc dot gnu.org> --- The below patch should fix it for all such options, I am testing it now. The old_kind shouldn't demand that the diagnostic must be a warning or an error specifically, it just needs to note that the diagnostic is enabled or disabled, and then let the frontend determine what type it is like it normally does. diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index addd6606eaa..99921a10b7b 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -1126,8 +1126,7 @@ classify_diagnostic (const diagnostic_context *context, old_kind = !context->m_option_enabled (option_index, context->m_lang_mask, context->m_option_state) - ? DK_IGNORED : (context->warning_as_error_requested_p () - ? DK_ERROR : DK_WARNING); + ? DK_IGNORED : DK_ANY; m_classify_diagnostic[option_index] = old_kind; } @@ -1469,7 +1468,15 @@ diagnostic_context::diagnostic_enabled (diagnostic_info *diagnostic) option. */ if (diag_class == DK_UNSPECIFIED && !option_unspecified_p (diagnostic->option_index)) - diagnostic->kind = m_option_classifier.get_current_override (diagnostic->option_index); + { + const diagnostic_t new_kind + = m_option_classifier.get_current_override (diagnostic->option_index); + if (new_kind != DK_ANY) + /* DK_ANY means the diagnostic is not to be ignored, but we don't want + to change it specifically to DK_ERROR or DK_WARNING; we want to + preserve whatever the caller has specified. */ + diagnostic->kind = new_kind; + } /* This allows for future extensions, like temporarily disabling warnings for ranges of source code. */ diff --git a/gcc/diagnostic.def b/gcc/diagnostic.def index 813b8daa4cc..e889eca7757 100644 --- a/gcc/diagnostic.def +++ b/gcc/diagnostic.def @@ -53,3 +53,8 @@ DEFINE_DIAGNOSTIC_KIND (DK_WERROR, "error: ", NULL) /* This is like DK_ICE, but backtrace is not printed. Used in the driver when reporting fatal signal in the compiler. */ DEFINE_DIAGNOSTIC_KIND (DK_ICE_NOBT, "internal compiler error: ", "error") + +/* This is used internally to indicate that a diagnostic is not to be ignored, + without mandating it be a specific type, so that it can be an error or + warning or otherwise, as the current context requires. */ +DEFINE_DIAGNOSTIC_KIND (DK_ANY, "", NULL)