[libcxx-commits] [libcxx] [libcxxabi] [libc++][NFC] Remoe _LIBCPP_CONSTINIT (PR #171802)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 11 03:01:43 PST 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/171802

`_LIBCPP_CONSTINIT` is only ever used inside `src/`, so we can just replace it with `constinit` instead.


>From e5760438d6ed3d49f5fcf55f2f8dcc67ccf92c56 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 11 Dec 2025 12:01:00 +0100
Subject: [PATCH] [libc++][NFC] Remoe _LIBCPP_CONSTINIT

---
 libcxx/.clang-format              | 1 -
 libcxx/include/__config           | 8 --------
 libcxxabi/src/cxa_guard_impl.h    | 2 +-
 libcxxabi/src/fallback_malloc.cpp | 4 ++--
 4 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/libcxx/.clang-format b/libcxx/.clang-format
index 9557b955cd72c..6d7ff0f4f2822 100644
--- a/libcxx/.clang-format
+++ b/libcxx/.clang-format
@@ -26,7 +26,6 @@ AttributeMacros: [
                   '_LIBCPP_CONSTEXPR_SINCE_CXX20',
                   '_LIBCPP_CONSTEXPR_SINCE_CXX23',
                   '_LIBCPP_CONSTEXPR',
-                  '_LIBCPP_CONSTINIT',
                   '_LIBCPP_DEPRECATED_IN_CXX11',
                   '_LIBCPP_DEPRECATED_IN_CXX14',
                   '_LIBCPP_DEPRECATED_IN_CXX17',
diff --git a/libcxx/include/__config b/libcxx/include/__config
index e758acfa870ae..643bd4c8f1742 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -745,14 +745,6 @@ typedef __char32_t char32_t;
 #    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 #  endif
 
-#  if _LIBCPP_STD_VER >= 20
-#    define _LIBCPP_CONSTINIT constinit
-#  elif __has_attribute(__require_constant_initialization__)
-#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
-#  else
-#    define _LIBCPP_CONSTINIT
-#  endif
-
 #  if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
 // The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
 // which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
diff --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h
index 191a589176b1a..5f51e81c57209 100644
--- a/libcxxabi/src/cxa_guard_impl.h
+++ b/libcxxabi/src/cxa_guard_impl.h
@@ -637,7 +637,7 @@ struct GlobalStatic {
   static T instance;
 };
 template <class T>
-_LIBCPP_CONSTINIT T GlobalStatic<T>::instance = {};
+constinit T GlobalStatic<T>::instance = {};
 
 enum class Implementation { NoThreads, GlobalMutex, Futex };
 
diff --git a/libcxxabi/src/fallback_malloc.cpp b/libcxxabi/src/fallback_malloc.cpp
index 6a261e6f009fe..81195c9a4dc17 100644
--- a/libcxxabi/src/fallback_malloc.cpp
+++ b/libcxxabi/src/fallback_malloc.cpp
@@ -35,9 +35,9 @@ namespace {
 
 // When POSIX threads are not available, make the mutex operations a nop
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-static _LIBCPP_CONSTINIT std::__libcpp_mutex_t heap_mutex = _LIBCPP_MUTEX_INITIALIZER;
+static constinit std::__libcpp_mutex_t heap_mutex = _LIBCPP_MUTEX_INITIALIZER;
 #else
-static _LIBCPP_CONSTINIT void* heap_mutex = 0;
+static constinit void* heap_mutex = 0;
 #endif
 
 class mutexor {



More information about the libcxx-commits mailing list