]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: exception spec and stdlib specialization
authorJason Merrill <jason@redhat.com>
Fri, 6 Sep 2024 19:28:53 +0000 (15:28 -0400)
committerJason Merrill <jason@redhat.com>
Sat, 7 Sep 2024 22:54:13 +0000 (18:54 -0400)
commit7cebc6384a0ad63d444029472a8ed1afe965bbbc
treeb409b60ed2ec77c5484dc1b6471266cbbac3ec8f
parent69d82c1dccb3583464228eb5449e29918eeb4ee4
c++: exception spec and stdlib specialization

We were silently accepting the pr65923.C specialization of std::swap with
the wrong exception specification; it should be declared noexcept.  Let's
limit ignoring mismatch with system headers to extern "C" functions so we
get a diagnostic for the C++ library.

In the case of an omitted exception-specification, let's also lower the
error to a pedwarn, and copy the missing spec over, to avoid a hard break
for code that accidentally relied on the old behavior.

...except extern "C" functions keep the new spec, to avoid breaking dubious
code like noexcept-type19.C.

gcc/cp/ChangeLog:

* decl.cc (check_redeclaration_exception_specification): Remove
OPT_Wsystem_headers from pedwarn when the old declaration is
in a system header.  Also check std namespace.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/pr65923.C: Add noexcept.
* g++.dg/cpp1z/aligned-new3.C: Expect pedwarn.
* g++.dg/cpp1z/noexcept-type19.C: Add comment.
gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp1z/aligned-new3.C
gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C
gcc/testsuite/g++.dg/diagnostic/pr65923.C