summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-Fay.ORG>2024-02-02 09:41:40 -0700
committerDimitry Andric <dim@FreeBSD.org>2025-12-30 00:46:45 +0100
commitcd2a65a60701d806e8ebbf97b6c77c880e0c9746 (patch)
treef484fc9f8e43fa1717d0f7288feb8dac311488c6
parent0487408a76c66b8bf7edddf1ec8025f60c6d0474 (diff)
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)
-rw-r--r--sys/sys/cdefs.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index 8fd07ce85a05..96a3742c4a1d 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -395,6 +395,17 @@
#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
* for it.