]> Savannah Git Hosting - gnulib.git/commitdiff
Don't use 'throw ()' in C++ 11 or newer.
authorBruno Haible <bruno@clisp.org>
Thu, 7 Sep 2023 20:22:43 +0000 (22:22 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 14 Sep 2023 10:01:57 +0000 (12:01 +0200)
* lib/stddef.in.h (_GL_ATTRIBUTE_NOTHROW):  Provide fallback definition.
(abort): Declare with _GL_ATTRIBUTE_NOTHROW instead of throw().
* lib/malloc.in.h (rpl_free, free): Likewise.
* lib/stdlib.in.h (free): Likewise.
* lib/string.in.h (rpl_free, free, memchr, memrchr, rawmemchr,
strchrnul, strpbrk, strstr, strcasestr): Likewise.
* lib/wchar.in.h (rpl_free, free): Likewise.
* lib/getopt-cdefs.in.h (__THROW): Define to noexcept(true) for C++ 11
or newer.
* lib/md5.h (__THROW): Likewise.

ChangeLog
lib/getopt-cdefs.in.h
lib/malloc.in.h
lib/md5.h
lib/stddef.in.h
lib/stdlib.in.h
lib/string.in.h
lib/wchar.in.h

index 7e4a5631d4bbd31f2cd330e6ab6001795c4223fd..1decc34c86c9187fc50032a051cc86b323d1e518 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2023-09-07  Bruno Haible  <bruno@clisp.org>
+
+       Don't use 'throw ()' in C++ 11 or newer.
+       * lib/stddef.in.h (_GL_ATTRIBUTE_NOTHROW):  Provide fallback definition.
+       (abort): Declare with _GL_ATTRIBUTE_NOTHROW instead of throw().
+       * lib/malloc.in.h (rpl_free, free): Likewise.
+       * lib/stdlib.in.h (free): Likewise.
+       * lib/string.in.h (rpl_free, free, memchr, memrchr, rawmemchr,
+       strchrnul, strpbrk, strstr, strcasestr): Likewise.
+       * lib/wchar.in.h (rpl_free, free): Likewise.
+       * lib/getopt-cdefs.in.h (__THROW): Define to noexcept(true) for C++ 11
+       or newer.
+       * lib/md5.h (__THROW): Likewise.
+
 2023-09-07  Bruno Haible  <bruno@clisp.org>
 
        uchar: Fix references to overridden functions with GNULIB_NAMESPACE.
index e76c78cb212c99c2f4af56168cf55fedcadf828e..1a666ebb7bfb9e969ac424449538e30c672a5d30 100644 (file)
 
 #ifndef __THROW
 # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
-#  define __THROW       throw ()
+#  if __cplusplus >= 201103L
+#   define __THROW      noexcept (true)
+#  else
+#   define __THROW      throw ()
+#  endif
 # else
 #  define __THROW
 # endif
index a3393894ea2a7c9d981fbdde15ff227bba3c91fb..de0967b591c3e2c623873ffe01d149111822ed33 100644 (file)
@@ -95,7 +95,7 @@
       && !(defined __cplusplus && defined GNULIB_NAMESPACE))
 /* We can't do '#define free rpl_free' here.  */
 #  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void rpl_free (void *) throw ();
+_GL_EXTERN_C void rpl_free (void *) _GL_ATTRIBUTE_NOTHROW;
 #  else
 _GL_EXTERN_C void rpl_free (void *);
 #  endif
@@ -110,7 +110,7 @@ _GL_EXTERN_C
      void __cdecl free (void *);
 #  else
 #   if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void free (void *) throw ();
+_GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
 #   else
 _GL_EXTERN_C void free (void *);
 #   endif
@@ -125,7 +125,7 @@ _GL_EXTERN_C
      void __cdecl free (void *);
 # else
 #  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void free (void *) throw ();
+_GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
 #  else
 _GL_EXTERN_C void free (void *);
 #  endif
index 6ddf0091489497598a7614b2d58ee816d461c969..f8fbda78858bfde5b4c43e819ca173a5afd8c20c 100644 (file)
--- a/lib/md5.h
+++ b/lib/md5.h
 
 #ifndef __THROW
 # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
-#  define __THROW       throw ()
+#  if __cplusplus >= 201103L
+#   define __THROW      noexcept (true)
+#  else
+#   define __THROW      throw ()
+#  endif
 # else
 #  define __THROW
 # endif
index bb18198c987976293a465d6d6302a5fd04225758..190fd575d8d9687e0d6ae183a003877bfc62bdbe 100644 (file)
@@ -101,11 +101,33 @@ typedef long max_align_t;
 #  ifndef _@GUARD_PREFIX@_STDDEF_H
 #   define _@GUARD_PREFIX@_STDDEF_H
 
-/* This file uses _Noreturn.  */
+/* This file uses _Noreturn, _GL_ATTRIBUTE_NOTHROW.  */
 #if !_GL_CONFIG_H_INCLUDED
  #error "Please include config.h first."
 #endif
 
+/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
+ */
+#ifndef _GL_ATTRIBUTE_NOTHROW
+# if defined __cplusplus
+#  if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4
+#   if __cplusplus >= 201103L
+#    define _GL_ATTRIBUTE_NOTHROW noexcept (true)
+#   else
+#    define _GL_ATTRIBUTE_NOTHROW throw ()
+#   endif
+#  else
+#   define _GL_ATTRIBUTE_NOTHROW
+#  endif
+# else
+#  if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__
+#   define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
+#  else
+#   define _GL_ATTRIBUTE_NOTHROW
+#  endif
+# endif
+#endif
+
 /* Some platforms lack wchar_t.  */
 #if !@HAVE_WCHAR_T@
 # define wchar_t int
@@ -178,7 +200,7 @@ extern
 _Noreturn
 void abort (void)
 #  if defined __cplusplus && (__GLIBC__ >= 2)
-throw ()
+_GL_ATTRIBUTE_NOTHROW
 #  endif
 ;
 #  define unreachable() abort ()
index 57603716b6b8c123d88eb2eb0d38235816200c9d..b9838c7d5ee9c8754e979d5f4711bd5481f1513d 100644 (file)
@@ -223,7 +223,7 @@ _GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
 #   define free rpl_free
 #  endif
 #  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_FUNCDECL_RPL (free, void, (void *ptr) throw ());
+_GL_FUNCDECL_RPL (free, void, (void *ptr) _GL_ATTRIBUTE_NOTHROW);
 #  else
 _GL_FUNCDECL_RPL (free, void, (void *ptr));
 #  endif
index ee1d3c1420eb63d9ee6f68e18b23f24c20648d28..8b62ae8fc9ed411993c219fcf8c43c347b42cdd8 100644 (file)
       && !(defined __cplusplus && defined GNULIB_NAMESPACE))
 /* We can't do '#define free rpl_free' here.  */
 #  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void rpl_free (void *) throw ();
+_GL_EXTERN_C void rpl_free (void *) _GL_ATTRIBUTE_NOTHROW;
 #  else
 _GL_EXTERN_C void rpl_free (void *);
 #  endif
@@ -171,7 +171,7 @@ _GL_EXTERN_C
      void __cdecl free (void *);
 #  else
 #   if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void free (void *) throw ();
+_GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
 #   else
 _GL_EXTERN_C void free (void *);
 #   endif
@@ -186,7 +186,7 @@ _GL_EXTERN_C
      void __cdecl free (void *);
 # else
 #  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void free (void *) throw ();
+_GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
 #  else
 _GL_EXTERN_C void free (void *);
 #  endif
@@ -289,9 +289,12 @@ _GL_CXXALIAS_SYS_CAST2 (memchr,
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
          || defined __clang__)
-_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n) throw ());
+_GL_CXXALIASWARN1 (memchr, void *,
+                   (void *__s, int __c, size_t __n)
+                   _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (memchr, void const *,
-                   (void const *__s, int __c, size_t __n) throw ());
+                   (void const *__s, int __c, size_t __n)
+                   _GL_ATTRIBUTE_NOTHROW);
 # elif __GLIBC__ >= 2
 _GL_CXXALIASWARN (memchr);
 # endif
@@ -391,8 +394,12 @@ _GL_CXXALIAS_SYS_CAST2 (memrchr,
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
          || defined __clang__)
-_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t) throw ());
-_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t) throw ());
+_GL_CXXALIASWARN1 (memrchr, void *,
+                   (void *, int, size_t)
+                   _GL_ATTRIBUTE_NOTHROW);
+_GL_CXXALIASWARN1 (memrchr, void const *,
+                   (void const *, int, size_t)
+                   _GL_ATTRIBUTE_NOTHROW);
 # elif __GLIBC__ >= 2
 _GL_CXXALIASWARN (memrchr);
 # endif
@@ -439,9 +446,12 @@ _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
          || defined __clang__)
-_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in) throw ());
+_GL_CXXALIASWARN1 (rawmemchr, void *,
+                   (void *__s, int __c_in)
+                   _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (rawmemchr, void const *,
-                   (void const *__s, int __c_in) throw ());
+                   (void const *__s, int __c_in)
+                   _GL_ATTRIBUTE_NOTHROW);
 # else
 _GL_CXXALIASWARN (rawmemchr);
 # endif
@@ -561,9 +571,12 @@ _GL_CXXALIAS_SYS_CAST2 (strchrnul,
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
          || defined __clang__)
-_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in) throw ());
+_GL_CXXALIASWARN1 (strchrnul, char *,
+                   (char *__s, int __c_in)
+                   _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (strchrnul, char const *,
-                   (char const *__s, int __c_in) throw ());
+                   (char const *__s, int __c_in)
+                   _GL_ATTRIBUTE_NOTHROW);
 # elif __GLIBC__ >= 2
 _GL_CXXALIASWARN (strchrnul);
 # endif
@@ -797,9 +810,12 @@ _GL_CXXALIAS_SYS_CAST2 (strpbrk,
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
          || defined __clang__)
-_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept) throw ());
+_GL_CXXALIASWARN1 (strpbrk, char *,
+                   (char *__s, char const *__accept)
+                   _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (strpbrk, char const *,
-                   (char const *__s, char const *__accept) throw ());
+                   (char const *__s, char const *__accept)
+                   _GL_ATTRIBUTE_NOTHROW);
 # elif __GLIBC__ >= 2
 _GL_CXXALIASWARN (strpbrk);
 # endif
@@ -907,9 +923,11 @@ _GL_CXXALIAS_SYS_CAST2 (strstr,
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
          || defined __clang__)
 _GL_CXXALIASWARN1 (strstr, char *,
-                   (char *haystack, const char *needle) throw ());
+                   (char *haystack, const char *needle)
+                   _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (strstr, const char *,
-                   (const char *haystack, const char *needle) throw ());
+                   (const char *haystack, const char *needle)
+                   _GL_ATTRIBUTE_NOTHROW);
 # elif __GLIBC__ >= 2
 _GL_CXXALIASWARN (strstr);
 # endif
@@ -958,9 +976,11 @@ _GL_CXXALIAS_SYS_CAST2 (strcasestr,
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
          || defined __clang__)
 _GL_CXXALIASWARN1 (strcasestr, char *,
-                   (char *haystack, const char *needle) throw ());
+                   (char *haystack, const char *needle)
+                   _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (strcasestr, const char *,
-                   (const char *haystack, const char *needle) throw ());
+                   (const char *haystack, const char *needle)
+                   _GL_ATTRIBUTE_NOTHROW);
 # elif __GLIBC__ >= 2
 _GL_CXXALIASWARN (strcasestr);
 # endif
index 5d6b2b76bb46015551f212e608be03e4503cfef9..754b447baa97ccada0dadb9e4b1abca941aaeeef 100644 (file)
@@ -218,7 +218,7 @@ typedef int rpl_mbstate_t;
       && !(defined __cplusplus && defined GNULIB_NAMESPACE))
 /* We can't do '#define free rpl_free' here.  */
 #  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void rpl_free (void *) throw ();
+_GL_EXTERN_C void rpl_free (void *) _GL_ATTRIBUTE_NOTHROW;
 #  else
 _GL_EXTERN_C void rpl_free (void *);
 #  endif
@@ -233,7 +233,7 @@ _GL_EXTERN_C
      void __cdecl free (void *);
 #  else
 #   if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void free (void *) throw ();
+_GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
 #   else
 _GL_EXTERN_C void free (void *);
 #   endif
@@ -248,7 +248,7 @@ _GL_EXTERN_C
      void __cdecl free (void *);
 # else
 #  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
-_GL_EXTERN_C void free (void *) throw ();
+_GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
 #  else
 _GL_EXTERN_C void free (void *);
 #  endif