[libcxx-commits] [libcxx] [libc++] Remove <cstdlib> include from <exception> (PR #166340)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 4 02:25:55 PST 2025
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/166340
>From 728e5850fbec51cfb3c72900c64d67d139f61c23 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 4 Nov 2025 10:17:32 +0100
Subject: [PATCH] [libc++] Remove <cstdlib> include from <exception>
---
libcxx/include/__exception/exception_ptr.h | 7 ++++---
libcxx/include/exception | 5 ++++-
libcxx/test/libcxx/transitive_includes/cxx26.csv | 1 -
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__exception/exception_ptr.h b/libcxx/include/__exception/exception_ptr.h
index e78126ea23852..aef036a2c9586 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -11,6 +11,7 @@
#include <__config>
#include <__cstddef/nullptr_t.h>
+#include <__cstddef/size_t.h>
#include <__exception/operations.h>
#include <__memory/addressof.h>
#include <__memory/construct_at.h>
@@ -18,7 +19,7 @@
#include <__type_traits/is_pointer.h>
#include <__utility/move.h>
#include <__utility/swap.h>
-#include <cstdlib>
+#include <__verbose_abort>
#include <typeinfo>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -35,7 +36,7 @@ _LIBCPP_PUSH_MACROS
namespace __cxxabiv1 {
extern "C" {
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
+_LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(std::size_t) throw();
_LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
struct __cxa_exception;
@@ -174,7 +175,7 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
# else // !_LIBCPP_HAS_EXCEPTIONS
template <class _Ep>
_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep) _NOEXCEPT {
- std::abort();
+ _LIBCPP_VERBOSE_ABORT("make_exception_ptr was called in -fno-exceptions mode");
}
# endif // _LIBCPP_HAS_EXCEPTIONS
diff --git a/libcxx/include/exception b/libcxx/include/exception
index 74229cd16c006..0b2372e571e99 100644
--- a/libcxx/include/exception
+++ b/libcxx/include/exception
@@ -93,10 +93,13 @@ template <class E> void rethrow_if_nested(const E& e);
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <cstddef>
-# include <cstdlib>
# include <new>
# include <type_traits>
# endif
+
+# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
+# include <cstdlib>
+# endif
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
#endif // _LIBCPP_EXCEPTION
diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index d047b29b63cc6..8c3e1f0a97dfe 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -245,7 +245,6 @@ deque stdexcept
deque tuple
deque version
exception cstdint
-exception cstdlib
exception typeinfo
exception version
execution version
More information about the libcxx-commits
mailing list