clang (at least in version >= 4), in C++ mode, supports the 'throw ()' 
declaration
on functions, and uses it to optimize try/catch statements at the caller site.


2020-08-16  Bruno Haible  <br...@clisp.org>

        Use 'throw ()' for optimization in C++ mode also on clang.
        * lib/cdefs.h (__THROW): Define to 'throw ()' also on clang.
        * lib/getopt-cdefs.in.h (__THROW): Likewise.
        * lib/md5.h (__THROW): Likewise.

diff --git a/lib/cdefs.h b/lib/cdefs.h
index dfa935f..b7f60c1 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -85,7 +85,7 @@
 #  define __NTH(fct)   __attribute__ ((__nothrow__ __LEAF)) fct
 #  define __NTHNL(fct)  __attribute__ ((__nothrow__)) fct
 # else
-#  if defined __cplusplus && __GNUC_PREREQ (2,8)
+#  if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
 #   define __THROW     throw ()
 #   define __THROWNL   throw ()
 #   define __NTH(fct)  __LEAF_ATTR fct throw ()
diff --git a/lib/getopt-cdefs.in.h b/lib/getopt-cdefs.in.h
index 89a7b85..641e5e9 100644
--- a/lib/getopt-cdefs.in.h
+++ b/lib/getopt-cdefs.in.h
@@ -57,7 +57,7 @@
 #endif
 
 #ifndef __THROW
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
+# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
 #  define __THROW       throw ()
 # else
 #  define __THROW
diff --git a/lib/md5.h b/lib/md5.h
index 0c8b929..4631035 100644
--- a/lib/md5.h
+++ b/lib/md5.h
@@ -40,7 +40,7 @@
 #endif
 
 #ifndef __THROW
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
+# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
 #  define __THROW       throw ()
 # else
 #  define __THROW


Reply via email to