[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 23:06:36 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 1/2] [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
>From 308049b0bc9008faab674c5e1fc95155c04a5dfb Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Fri, 6 Dec 2024 23:05:39 -0800
Subject: [PATCH 2/2] Simplify __NOEXCEPT conditionalization
---
libc/include/__llvm-libc-common.h | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index 8e4a3a5c76b722..d54ee7b9f91f32 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -53,12 +53,9 @@
#define __restrict restrict // C99 and above support the restrict keyword.
#undef __NOEXCEPT
-#if defined(__has_attribute)
-#if __has_attribute(__nothrow__)
+#ifdef __GNUC__
#define __NOEXCEPT __attribute__((__nothrow__))
-#endif // __has_attribute(__nothrow__)
-#endif // defined(__has_attribute)
-#ifndef __NOEXCEPT
+#else
#define __NOEXCEPT
#endif
More information about the libc-commits
mailing list