[libc-commits] [libc] [libc] Add noexcept to aligned_alloc declaration in full-build mode (PR #191236)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Thu Apr 30 06:25:22 PDT 2026


https://github.com/kaladron updated https://github.com/llvm/llvm-project/pull/191236

>From a708a03a3bdfbb8ec10adc43ebe337fe8b51dd96 Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Thu, 9 Apr 2026 16:39:22 +0100
Subject: [PATCH 1/2] [libc] Add noexcept to aligned_alloc declaration in
 full-build mode

The extern "C" declaration of aligned_alloc in the proxy header
lacked a noexcept specifier, producing warnings when compiled as
C++. Added a __cplusplus guard so C++ gets noexcept while C
compilation remains unaffected.
---
 libc/hdr/func/aligned_alloc.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libc/hdr/func/aligned_alloc.h b/libc/hdr/func/aligned_alloc.h
index b3436dfee1f23..3c197f4671a76 100644
--- a/libc/hdr/func/aligned_alloc.h
+++ b/libc/hdr/func/aligned_alloc.h
@@ -11,7 +11,11 @@
 
 #ifdef LIBC_FULL_BUILD
 #include "hdr/types/size_t.h"
+#ifdef __cplusplus
+extern "C" void *aligned_alloc(size_t, size_t) noexcept;
+#else
 extern "C" void *aligned_alloc(size_t, size_t);
+#endif
 
 #else // Overlay mode
 

>From d1236d1337d697b86fb4aa621c49b28b9cb2993c Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Thu, 30 Apr 2026 13:55:16 +0100
Subject: [PATCH 2/2] [libc] Use __llvm_libc_common.h macros in func proxy
 headers (#191236)

Replaced raw extern "C" and noexcept with __BEGIN_C_DECLS,
__END_C_DECLS, and __NOEXCEPT from __llvm-libc-common.h in
all four func proxy headers: aligned_alloc.h, free.h, malloc.h,
and realloc.h.

This addresses the review feedback and ensures C compatibility
for the full-build declarations.
---
 libc/hdr/func/aligned_alloc.h | 11 ++++++-----
 libc/hdr/func/free.h          |  6 +++++-
 libc/hdr/func/malloc.h        |  5 ++++-
 libc/hdr/func/realloc.h       |  5 ++++-
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/libc/hdr/func/aligned_alloc.h b/libc/hdr/func/aligned_alloc.h
index 3c197f4671a76..b0aafa29f5b1d 100644
--- a/libc/hdr/func/aligned_alloc.h
+++ b/libc/hdr/func/aligned_alloc.h
@@ -10,12 +10,13 @@
 #define LLVM_LIBC_HDR_FUNC_ALIGNED_ALLOC_H
 
 #ifdef LIBC_FULL_BUILD
+
+#include "include/__llvm-libc-common.h"
 #include "hdr/types/size_t.h"
-#ifdef __cplusplus
-extern "C" void *aligned_alloc(size_t, size_t) noexcept;
-#else
-extern "C" void *aligned_alloc(size_t, size_t);
-#endif
+
+__BEGIN_C_DECLS
+void *aligned_alloc(size_t, size_t) __NOEXCEPT;
+__END_C_DECLS
 
 #else // Overlay mode
 
diff --git a/libc/hdr/func/free.h b/libc/hdr/func/free.h
index 316556b21e3b0..20e85c85d80a8 100644
--- a/libc/hdr/func/free.h
+++ b/libc/hdr/func/free.h
@@ -11,7 +11,11 @@
 
 #ifdef LIBC_FULL_BUILD
 
-extern "C" void free(void *) noexcept;
+#include "include/__llvm-libc-common.h"
+
+__BEGIN_C_DECLS
+void free(void *) __NOEXCEPT;
+__END_C_DECLS
 
 #else // Overlay mode
 
diff --git a/libc/hdr/func/malloc.h b/libc/hdr/func/malloc.h
index 8281021f79969..d3fab8461c5c0 100644
--- a/libc/hdr/func/malloc.h
+++ b/libc/hdr/func/malloc.h
@@ -11,9 +11,12 @@
 
 #ifdef LIBC_FULL_BUILD
 
+#include "include/__llvm-libc-common.h"
 #include "hdr/types/size_t.h"
 
-extern "C" void *malloc(size_t) noexcept;
+__BEGIN_C_DECLS
+void *malloc(size_t) __NOEXCEPT;
+__END_C_DECLS
 
 #else // Overlay mode
 
diff --git a/libc/hdr/func/realloc.h b/libc/hdr/func/realloc.h
index ecb29541fe34a..129a111e22d23 100644
--- a/libc/hdr/func/realloc.h
+++ b/libc/hdr/func/realloc.h
@@ -11,9 +11,12 @@
 
 #ifdef LIBC_FULL_BUILD
 
+#include "include/__llvm-libc-common.h"
 #include "hdr/types/size_t.h"
 
-extern "C" void *realloc(void *ptr, size_t new_size) noexcept;
+__BEGIN_C_DECLS
+void *realloc(void *ptr, size_t new_size) __NOEXCEPT;
+__END_C_DECLS
 
 #else // Overlay mode
 



More information about the libc-commits mailing list