aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2025-01-09 15:12:07 -0500
committerJason Merrill <jason@redhat.com>2025-01-09 16:23:05 -0500
commit3cae3a80695e5aabd7353c02e179c997158eef30 (patch)
tree0c770a90435f38ddffcbecfdb05e0290b3eb4781 /gcc
parent424a9ac45ab1a80359b22ee30d2815fb0f2c5149 (diff)
downloadgcc-3cae3a80695e5aabd7353c02e179c997158eef30.zip
gcc-3cae3a80695e5aabd7353c02e179c997158eef30.tar.gz
gcc-3cae3a80695e5aabd7353c02e179c997158eef30.tar.bz2
c++: be permissive about eh spec mismatch for op new
r15-3532 made us more strict about exception-specification mismatches with the standard library, but let's still be permissive about operator new, since previously you needed to say throw(std::bad_alloc). gcc/cp/ChangeLog: * decl.cc (check_redeclaration_exception_specification): Be more lenient about ::operator new. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept88.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/decl.cc11
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/noexcept88.C9
2 files changed, 18 insertions, 2 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 288da65..5c6a499 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -1398,7 +1398,14 @@ check_redeclaration_exception_specification (tree new_decl,
location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
auto_diagnostic_group d;
- if (DECL_IN_SYSTEM_HEADER (old_decl) && DECL_EXTERN_C_P (old_decl))
+ /* Be permissive about C++98 vs C++11 operator new declarations. */
+ bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
+ && CP_DECL_CONTEXT (new_decl) == global_namespace
+ && (nothrow_spec_p (new_exceptions)
+ == nothrow_spec_p (old_exceptions)));
+
+ if (DECL_IN_SYSTEM_HEADER (old_decl)
+ && (global_new || DECL_EXTERN_C_P (old_decl)))
/* Don't fuss about the C library; the C library functions are not
specified to have exception specifications (just behave as if they
have them), but some implementations include them. */
@@ -1407,7 +1414,7 @@ check_redeclaration_exception_specification (tree new_decl,
/* We used to silently permit mismatched eh specs with
-fno-exceptions, so only complain if -pedantic. */
complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
- else if (!new_exceptions)
+ else if (!new_exceptions || global_new)
/* Reduce to pedwarn for omitted exception specification. No warning
flag for this; silence the warning by correcting the code. */
complained = pedwarn (new_loc, 0, msg, new_decl);
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept88.C b/gcc/testsuite/g++.dg/cpp0x/noexcept88.C
new file mode 100644
index 0000000..9b57fdd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept88.C
@@ -0,0 +1,9 @@
+// { dg-options -Wsystem-headers }
+
+#include <cstdlib>
+#include <new>
+
+void *operator new (std::size_t) throw (std::bad_alloc); // { dg-line decl }
+// { dg-error "dynamic exception spec" "" { target c++17 } decl }
+// { dg-warning "dynamic exception spec" "" { target { c++11 && { ! c++17 } } } decl }
+// { dg-warning "different exception spec" "" { target { c++11 && { ! c++17 } } } decl }