public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] Define __THROW to noexcept for C++11 and later
@ 2020-09-22 13:55 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2020-09-22 13:55 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d445d9ca8d961148ffde8ec597ecc0e050542024
commit d445d9ca8d961148ffde8ec597ecc0e050542024
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Sep 22 11:54:38 2020 +0100
Define __THROW to noexcept for C++11 and later
The __THROW macro and friends expand to "throw ()" for C++ code, but
that syntax is deprecated in C++11 and no longer supported at all since
C++20. In order for glibc headers to be compatible with C++20,
"noexcept" should be used instead.
This patch uses "noexcept (true)" rather than just "noexcept", which is
semantically equivalent, but avoids any possibility of parsing
ambiguities if the next preprocessor token happens to be an opening
parenthesis. This is probably unnecessary, but it seems safer to be
cautious.
Diff:
---
misc/sys/cdefs.h | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 19d9cc5cfe..6b9763a92a 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -58,10 +58,14 @@
# define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
# else
# if defined __cplusplus && __GNUC_PREREQ (2,8)
-# define __THROW throw ()
-# define __THROWNL throw ()
-# define __NTH(fct) __LEAF_ATTR fct throw ()
-# define __NTHNL(fct) fct throw ()
+# if __cplusplus >= 201103L
+# define __THROW noexcept (true)
+# else
+# define __THROW throw ()
+# endif
+# define __THROWNL __THROW
+# define __NTH(fct) __LEAF_ATTR fct __THROW
+# define __NTHNL(fct) fct __THROW
# else
# define __THROW
# define __THROWNL
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-22 13:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-22 13:55 [glibc] Define __THROW to noexcept for C++11 and later Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).