https://gcc.gnu.org/g:4e1e50458b2004d0f08ac8c64f89b85fc1a87057

commit r15-3573-g4e1e50458b2004d0f08ac8c64f89b85fc1a87057
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Tue Sep 10 16:59:29 2024 +0100

    libstdc++: Add missing exception specifications in tests
    
    Since r15-3532-g7cebc6384a0ad6 18_support/new_nothrow.cc fails in C++98 
mode because G++
    diagnoses missing exception specifications for the user-defined
    (de)allocation functions. Add throw(std::bad_alloc) and throw() for
    C++98 mode.
    
    Similarly, 26_numerics/headers/numeric/synopsis.cc fails in C++20 mode
    because the declarations of gcd and lcm are not noexcept.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/18_support/new_nothrow.cc (THROW_BAD_ALLOC): Define
            macro to add exception specifications for C++98 mode.
            (NOEXCEPT): Expand to throw() for C++98 mode.
            * testsuite/26_numerics/headers/numeric/synopsis.cc (gcd, lcm):
            Add noexcept.

Diff:
---
 libstdc++-v3/testsuite/18_support/new_nothrow.cc       | 18 ++++++++++--------
 .../testsuite/26_numerics/headers/numeric/synopsis.cc  |  4 ++--
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/testsuite/18_support/new_nothrow.cc 
b/libstdc++-v3/testsuite/18_support/new_nothrow.cc
index a3251f5ad64e..551b71dfa589 100644
--- a/libstdc++-v3/testsuite/18_support/new_nothrow.cc
+++ b/libstdc++-v3/testsuite/18_support/new_nothrow.cc
@@ -41,7 +41,15 @@ static void new_handler ()
         throw MyBadAlloc ();
 }
 
-void* operator new (size_t n)
+#if __cplusplus >= 201103L
+# define THROW_BAD_ALLOC noexcept(false)
+# define NOEXCEPT noexcept
+# else
+# define THROW_BAD_ALLOC throw(std::bad_alloc)
+# define NOEXCEPT throw()
+#endif
+
+void* operator new (size_t n) THROW_BAD_ALLOC
 {
     static size_t cntr;
 
@@ -64,12 +72,6 @@ void* operator new (size_t n)
     }
 }
 
-#if __cplusplus >= 201103L
-#define NOEXCEPT noexcept
-#else
-#define NOEXCEPT
-#endif
-
 void operator delete (void *p) NOEXCEPT
 {
     ++delete_called;
@@ -77,7 +79,7 @@ void operator delete (void *p) NOEXCEPT
         free (static_cast<size_t*>(p) - 1);
 }
 
-void* operator new[] (size_t n)
+void* operator new[] (size_t n) THROW_BAD_ALLOC
 {
     ++new_vec_called;
     return operator new(n);
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc 
b/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc
index 87670090f72f..8c33974c2e96 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc
@@ -161,10 +161,10 @@ namespace std {
 
 #if __cplusplus > 201703L
   template<class M, class N>
-    constexpr common_type_t<M,N> gcd(M m, N n);
+    constexpr common_type_t<M,N> gcd(M m, N n) noexcept;
 
   template<class M, class N>
-    constexpr common_type_t<M,N> lcm(M m, N n);
+    constexpr common_type_t<M,N> lcm(M m, N n) noexcept;
 
   template<class T>
     constexpr T midpoint(T a, T b) noexcept;

Reply via email to