git: c4290c35857d - stable/14 - sys/cdefs.h: add __noexcept and __noexcept_if
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 29 Dec 2025 23:29:56 UTC
The branch stable/14 has been updated by dim:
URL: https://cgit.FreeBSD.org/src/commit/?id=c4290c35857d46a880ae3873fef58aa98a20c087
commit c4290c35857d46a880ae3873fef58aa98a20c087
Author: Lexi Winter <ivy@FreeBSD.org>
AuthorDate: 2024-02-02 16:41:40 +0000
Commit: Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-12-29 21:47:53 +0000
sys/cdefs.h: add __noexcept and __noexcept_if
These macros provide the C++11 noexcept and noexcept(...) keywords if
we're compiling in a C++11 environment. Otherwise, they expand to an
empty string.
This will be used to add the required noexcept specifier to several libc
functions as required in C++11.
MFC after: 2 weeks
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1085
(cherry picked from commit 02b0d4b688cc4deb14cb6e7534a2a4958e48b753)
---
sys/sys/cdefs.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index 029eff437c8e..ed759029a53f 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -393,6 +393,17 @@
#endif
#endif
+/*
+ * noexcept keyword added in C++11.
+ */
+#if defined(__cplusplus) && __cplusplus >= 201103L
+#define __noexcept noexcept
+#define __noexcept_if(__c) noexcept(__c)
+#else
+#define __noexcept
+#define __noexcept_if(__c)
+#endif
+
/*
* nodiscard attribute added in C++17 and C23, but supported by both LLVM and
* GCC in earlier language versions, so we use __has_c{,pp}_attribute to test