https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90992

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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.

Tangentially, maybe the warning should not be given when a function is
explicitly marked noexcept(false). That's not the same as an implicit
potentially-throwing exception specification, and presumably the author did
that for a reason.

Reply via email to