diff options
author | Jason Merrill <jason@redhat.com> | 2020-01-26 00:37:24 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2020-01-26 21:26:17 -0500 |
commit | 5035cd662459b09605370f2ba41b2238119c69b1 (patch) | |
tree | 92714a88784da28de205aa1159b73407cf1601cd /gcc/cp/except.c | |
parent | cf17dcc6fc1f9f69d592952c2dd5796a5665bd5a (diff) | |
download | gcc-5035cd662459b09605370f2ba41b2238119c69b1.zip gcc-5035cd662459b09605370f2ba41b2238119c69b1.tar.gz gcc-5035cd662459b09605370f2ba41b2238119c69b1.tar.bz2 |
c++: Fix -Wnoexcept handling of system headers (PR90992).
The immediate issue here was that the second warning didn't depend on the
first one, so if the first location was in a system header, we'd
mysteriously give the second by itself.
It's also the case that the thing we care about being in a system header is
the function that we want to suggest adding 'noexcept' to, not the
noexcept-expression; it's useful to suggest adding noexcept to a user
function to satisfy a noexcept-expression in a system header.
PR c++/90992
* except.c (maybe_noexcept_warning): Check DECL_IN_SYSTEM_HEADER and
temporarily enable -Wsystem-headers. Change second warning to
conditional inform.
Diffstat (limited to 'gcc/cp/except.c')
-rw-r--r-- | gcc/cp/except.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 0b40234..788b96d 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -1165,13 +1165,17 @@ static GTY(()) vec<pending_noexcept, va_gc> *pending_noexcept_checks; static void maybe_noexcept_warning (tree fn) { - if (TREE_NOTHROW (fn)) + if (TREE_NOTHROW (fn) + && (!DECL_IN_SYSTEM_HEADER (fn) + || global_dc->dc_warn_system_headers)) { - 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); + temp_override<bool> s (global_dc->dc_warn_system_headers, true); + auto_diagnostic_group d; + if (warning (OPT_Wnoexcept, "noexcept-expression evaluates to %<false%> " + "because of a call to %qD", fn)) + inform (DECL_SOURCE_LOCATION (fn), + "but %qD does not throw; perhaps " + "it should be declared %<noexcept%>", fn); } } |