https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90992
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #4) > This suppresses the second warning if the first is suppressed: > > --- a/gcc/cp/except.c > +++ b/gcc/cp/except.c > @@ -1158,11 +1158,11 @@ maybe_noexcept_warning (tree fn) > { > if (TREE_NOTHROW (fn)) > { > - warning (OPT_Wnoexcept, "noexcept-expression evaluates to %<false%> " > - "because of a call to %qD", fn); > - warning_at (DECL_SOURCE_LOCATION (fn), OPT_Wnoexcept, > - "but %qD does not throw; perhaps " > - "it should be declared %<noexcept%>", fn); > + if (warning (OPT_Wnoexcept, "noexcept-expression evaluates to > %<false%> " > + "because of a call to %qD", fn)) > + warning_at (DECL_SOURCE_LOCATION (fn), OPT_Wnoexcept, > + "but %qD does not throw; perhaps " > + "it should be declared %<noexcept%>", fn); > } > } > > > > And this makes the first warning depend on whether the second one is in a > system header: > > --- a/gcc/cp/except.c > +++ b/gcc/cp/except.c > @@ -1158,11 +1158,20 @@ maybe_noexcept_warning (tree fn) > { > if (TREE_NOTHROW (fn)) > { > + location_t loc = DECL_SOURCE_LOCATION (fn); > + > + const bool warn_in_system_headers = global_dc->dc_warn_system_headers; > + if (in_system_header_at (input_location) && !in_system_header_at (loc) > + && !warn_in_system_headers) > + global_dc->dc_warn_system_headers = 1; > warning (OPT_Wnoexcept, "noexcept-expression evaluates to %<false%> " > "because of a call to %qD", fn); > - warning_at (DECL_SOURCE_LOCATION (fn), OPT_Wnoexcept, > + warning_at (loc, OPT_Wnoexcept, > "but %qD does not throw; perhaps " > "it should be declared %<noexcept%>", fn); > + if (in_system_header_at (input_location) && !in_system_header_at (loc) > + && !warn_in_system_headers) > + global_dc->dc_warn_system_headers = 0; > } > } > > > I don't know which of these is preferable, because I'm not sure if the point > of the warning is to suggest changing Automatic, or the code in the system > header. I'd say the second looks insufficient, system headers vs. non-system headers is just one of the reasons why a warning might be disabled, it can be #pragma GCC diagnostic ignored too. Purely from diagnostic POV, I'd say it should be auto_diagnostic_group d; if (warning (OPT_Wnoexcept, "...", fn)) inform (loc, "...", fn); Have you posted the patch? The warning has been added by Jason in r160842.