From c908ee044cf0a7be6a1dd60333f6fcda73c5ec77 Mon Sep 17 00:00:00 2001 From: William Huynh Date: Thu, 14 Aug 2025 16:39:47 +0100 Subject: [PATCH 1/2] [libc] Add _Returns_twice to C++ code Fixes issue with which requires _Returns_twice but in C++ mode --- libc/include/__llvm-libc-common.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h index c6fd33a55532c..b376b05df1678 100644 --- a/libc/include/__llvm-libc-common.h +++ b/libc/include/__llvm-libc-common.h @@ -47,6 +47,9 @@ #define __NOEXCEPT throw() #endif +#undef _Returns_twice +#define _Returns_twice [[gnu::returns_twice]] + // This macro serves as a generic cast implementation for use in both C and C++, // similar to `__BIONIC_CAST` in Android. #undef __LLVM_LIBC_CAST From 8e7da2c83af92378183588a47485726a08fb23a7 Mon Sep 17 00:00:00 2001 From: William Huynh Date: Mon, 18 Aug 2025 11:52:15 +0100 Subject: [PATCH 2/2] Add suggestion from @petrhoesk --- libc/include/__llvm-libc-common.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h index b376b05df1678..1fe3f4d2aea9c 100644 --- a/libc/include/__llvm-libc-common.h +++ b/libc/include/__llvm-libc-common.h @@ -48,7 +48,11 @@ #endif #undef _Returns_twice +#if __cplusplus >= 201103L #define _Returns_twice [[gnu::returns_twice]] +#else +#define _Returns_twice __attribute__((returns_twice)) +#endif // This macro serves as a generic cast implementation for use in both C and C++, // similar to `__BIONIC_CAST` in Android.