[libc-commits] [libc] [libc] Use __attribute__((__nothrow__)) for __NOEXCEPT in C (PR #114653)
Roland McGrath via libc-commits
libc-commits at lists.llvm.org
Fri Dec 6 22:56:05 PST 2024
https://github.com/frobtech updated https://github.com/llvm/llvm-project/pull/114653
>From 56570398674d0e5ded441d31e7901ca8bec3bb2d Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Sat, 2 Nov 2024 02:20:39 -0700
Subject: [PATCH] [libc] Use __attribute__((__nothrow__)) for __NOEXCEPT in C
Consistent with glibc headers, where `noexcept` is used in C++
(or `throw()` in older C++ which llvm-libc doesn't support) in
the public function declarations, __attribute__((__nothrow__)) is
used in C for compilers that support it.
---
libc/include/__llvm-libc-common.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index 3af0b08e9e8668..22dc78e6966e14 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -47,7 +47,14 @@
#define __restrict restrict // C99 and above support the restrict keyword.
#undef __NOEXCEPT
+#if defined(__has_attribute)
+#if __has_attribute(__nothrow__)
+#define __NOEXCEPT __attribute__((__nothrow__))
+#endif // __has_attribute(__nothrow__)
+#endif // defined(__has_attribute)
+#ifndef __NOEXCEPT
#define __NOEXCEPT
+#endif
#endif // __cplusplus
More information about the libc-commits
mailing list