[libc++] Move everything related solely to _LIBCPP_ASSERT to its own file
This is the first step towards disentangling the debug mode and assertions
in libc++. This patch doesn't make any functional change: it simply moves
_LIBCPP_ASSERT-related stuff to its own file so as to make it clear that
libc++ assertions and the debug mode are different things. Future patches
will make it possible to enable assertions without enabling the debug
mode.
Differential Revision: https://reviews.llvm.org/D119769
NOKEYCHECK=True
GitOrigin-RevId: f87aa19be64499308fc18f92d048c5fa2d3064d9
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index fb2b5be..1e5299f 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -99,6 +99,7 @@
__algorithm/unique_copy.h
__algorithm/unwrap_iter.h
__algorithm/upper_bound.h
+ __assert
__availability
__bit/bit_cast.h
__bit/byteswap.h
diff --git a/include/__algorithm/clamp.h b/include/__algorithm/clamp.h
index bfc96f8..b3762b8 100644
--- a/include/__algorithm/clamp.h
+++ b/include/__algorithm/clamp.h
@@ -10,8 +10,8 @@
#define _LIBCPP___ALGORITHM_CLAMP_H
#include <__algorithm/comp.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
diff --git a/include/__algorithm/comp_ref_type.h b/include/__algorithm/comp_ref_type.h
index 79dda0a..ed0ed59 100644
--- a/include/__algorithm/comp_ref_type.h
+++ b/include/__algorithm/comp_ref_type.h
@@ -9,6 +9,7 @@
#ifndef _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
#define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
+#include <__assert>
#include <__config>
#include <__debug>
#include <__utility/declval.h>
diff --git a/include/__algorithm/sample.h b/include/__algorithm/sample.h
index 0bf4fd5..5234961 100644
--- a/include/__algorithm/sample.h
+++ b/include/__algorithm/sample.h
@@ -10,8 +10,8 @@
#define _LIBCPP___ALGORITHM_SAMPLE_H
#include <__algorithm/min.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__random/uniform_int_distribution.h>
#include <iterator>
diff --git a/include/__assert b/include/__assert
new file mode 100644
index 0000000..d51512d
--- /dev/null
+++ b/include/__assert
@@ -0,0 +1,69 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___ASSERT
+#define _LIBCPP___ASSERT
+
+#include <__config>
+#include <iosfwd> // for std::string
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#if _LIBCPP_DEBUG_LEVEL >= 1
+# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : ::std::__libcpp_debug_function(::std::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
+#else
+# define _LIBCPP_ASSERT_IMPL(x, m) ((void)0)
+#endif
+
+// We do this dance because some of our tests re-define _LIBCPP_ASSERT to something else.
+// In the future, we should find other ways to test our assertions and disallow re-defining
+// _LIBCPP_ASSERT.
+#if !defined(_LIBCPP_ASSERT)
+# define _LIBCPP_ASSERT(x, m) _LIBCPP_ASSERT_IMPL(x, m)
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info {
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ __libcpp_debug_info()
+ : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m)
+ : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {}
+
+ _LIBCPP_FUNC_VIS string what() const;
+
+ const char* __file_;
+ int __line_;
+ const char* __pred_;
+ const char* __msg_;
+};
+
+/// __libcpp_debug_function_type - The type of the assertion failure handler.
+typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&);
+
+/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT
+/// fails.
+extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function;
+
+/// __libcpp_abort_debug_function - A debug handler that aborts when called.
+_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
+void __libcpp_abort_debug_function(__libcpp_debug_info const&);
+
+/// __libcpp_set_debug_function - Set the debug handler to the specified
+/// function.
+_LIBCPP_FUNC_VIS
+bool __libcpp_set_debug_function(__libcpp_debug_function_type __func);
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___ASSERT
diff --git a/include/__coroutine/coroutine_handle.h b/include/__coroutine/coroutine_handle.h
index ad399c8..4bf3237 100644
--- a/include/__coroutine/coroutine_handle.h
+++ b/include/__coroutine/coroutine_handle.h
@@ -9,8 +9,8 @@
#ifndef _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
#define _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__functional/hash.h>
#include <__memory/addressof.h>
#include <compare>
diff --git a/include/__debug b/include/__debug
index 5d0b5bf..207591c 100644
--- a/include/__debug
+++ b/include/__debug
@@ -10,6 +10,7 @@
#ifndef _LIBCPP_DEBUG_H
#define _LIBCPP_DEBUG_H
+#include <__assert>
#include <__config>
#include <iosfwd>
#include <type_traits>
@@ -24,57 +25,16 @@
# include <cstdlib>
#endif
-#if _LIBCPP_DEBUG_LEVEL == 0
+#if _LIBCPP_DEBUG_LEVEL == 0 || _LIBCPP_DEBUG_LEVEL == 1
# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
-# define _LIBCPP_ASSERT_IMPL(x, m) ((void)0)
-#elif _LIBCPP_DEBUG_LEVEL == 1
-# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
-# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : ::std::__libcpp_debug_function(::std::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
#elif _LIBCPP_DEBUG_LEVEL == 2
# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(::std::__libcpp_is_constant_evaluated() || (x), m)
-# define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : ::std::__libcpp_debug_function(::std::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
#else
# error _LIBCPP_DEBUG_LEVEL must be one of 0, 1, 2
#endif
-#if !defined(_LIBCPP_ASSERT)
-# define _LIBCPP_ASSERT(x, m) _LIBCPP_ASSERT_IMPL(x, m)
-#endif
-
_LIBCPP_BEGIN_NAMESPACE_STD
-struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info {
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- __libcpp_debug_info()
- : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m)
- : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {}
-
- _LIBCPP_FUNC_VIS string what() const;
-
- const char* __file_;
- int __line_;
- const char* __pred_;
- const char* __msg_;
-};
-
-/// __libcpp_debug_function_type - The type of the assertion failure handler.
-typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&);
-
-/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT
-/// fails.
-extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function;
-
-/// __libcpp_abort_debug_function - A debug handler that aborts when called.
-_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
-void __libcpp_abort_debug_function(__libcpp_debug_info const&);
-
-/// __libcpp_set_debug_function - Set the debug handler to the specified
-/// function.
-_LIBCPP_FUNC_VIS
-bool __libcpp_set_debug_function(__libcpp_debug_function_type __func);
-
#if _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY)
struct _LIBCPP_TYPE_VIS __c_node;
diff --git a/include/__filesystem/directory_iterator.h b/include/__filesystem/directory_iterator.h
index 4d45077..87bbbfa 100644
--- a/include/__filesystem/directory_iterator.h
+++ b/include/__filesystem/directory_iterator.h
@@ -10,9 +10,9 @@
#ifndef _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H
#define _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H
+#include <__assert>
#include <__availability>
#include <__config>
-#include <__debug>
#include <__filesystem/directory_entry.h>
#include <__filesystem/directory_options.h>
#include <__filesystem/path.h>
diff --git a/include/__filesystem/path_iterator.h b/include/__filesystem/path_iterator.h
index 0dfb04d..6f2baf8 100644
--- a/include/__filesystem/path_iterator.h
+++ b/include/__filesystem/path_iterator.h
@@ -10,9 +10,9 @@
#ifndef _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
#define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
+#include <__assert>
#include <__availability>
#include <__config>
-#include <__debug>
#include <__filesystem/path.h>
#include <__iterator/iterator_traits.h>
#include <cstddef>
diff --git a/include/__format/format_arg.h b/include/__format/format_arg.h
index 8db42cd..5e1565b 100644
--- a/include/__format/format_arg.h
+++ b/include/__format/format_arg.h
@@ -10,6 +10,7 @@
#ifndef _LIBCPP___FORMAT_FORMAT_ARG_H
#define _LIBCPP___FORMAT_FORMAT_ARG_H
+#include <__assert>
#include <__concepts/arithmetic.h>
#include <__config>
#include <__format/format_error.h>
diff --git a/include/__format/format_string.h b/include/__format/format_string.h
index 10fb471..32af660 100644
--- a/include/__format/format_string.h
+++ b/include/__format/format_string.h
@@ -10,8 +10,8 @@
#ifndef _LIBCPP___FORMAT_FORMAT_STRING_H
#define _LIBCPP___FORMAT_FORMAT_STRING_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__format/format_error.h>
#include <cstddef>
#include <cstdint>
diff --git a/include/__format/formatter.h b/include/__format/formatter.h
index 7e1ae31..f9e0b6c 100644
--- a/include/__format/formatter.h
+++ b/include/__format/formatter.h
@@ -13,6 +13,7 @@
#include <__algorithm/copy.h>
#include <__algorithm/fill_n.h>
#include <__algorithm/transform.h>
+#include <__assert>
#include <__availability>
#include <__config>
#include <__format/format_error.h>
diff --git a/include/__format/formatter_floating_point.h b/include/__format/formatter_floating_point.h
index c29cda4..aa32815 100644
--- a/include/__format/formatter_floating_point.h
+++ b/include/__format/formatter_floating_point.h
@@ -17,9 +17,9 @@
#include <__algorithm/min.h>
#include <__algorithm/rotate.h>
#include <__algorithm/transform.h>
+#include <__assert>
#include <__concepts/arithmetic.h>
#include <__config>
-#include <__debug>
#include <__format/format_error.h>
#include <__format/format_fwd.h>
#include <__format/format_string.h>
diff --git a/include/__format/formatter_integral.h b/include/__format/formatter_integral.h
index 4f82b34..8360826 100644
--- a/include/__format/formatter_integral.h
+++ b/include/__format/formatter_integral.h
@@ -14,6 +14,7 @@
#include <__algorithm/copy_n.h>
#include <__algorithm/fill_n.h>
#include <__algorithm/transform.h>
+#include <__assert>
#include <__config>
#include <__format/format_error.h>
#include <__format/format_fwd.h>
diff --git a/include/__format/formatter_pointer.h b/include/__format/formatter_pointer.h
index 15b6764..83d21e1 100644
--- a/include/__format/formatter_pointer.h
+++ b/include/__format/formatter_pointer.h
@@ -11,9 +11,9 @@
#define _LIBCPP___FORMAT_FORMATTER_POINTER_H
#include <__algorithm/copy.h>
+#include <__assert>
#include <__availability>
#include <__config>
-#include <__debug>
#include <__format/format_error.h>
#include <__format/format_fwd.h>
#include <__format/formatter.h>
diff --git a/include/__format/formatter_string.h b/include/__format/formatter_string.h
index 01e2baf..54aa121 100644
--- a/include/__format/formatter_string.h
+++ b/include/__format/formatter_string.h
@@ -10,6 +10,7 @@
#ifndef _LIBCPP___FORMAT_FORMATTER_STRING_H
#define _LIBCPP___FORMAT_FORMATTER_STRING_H
+#include <__assert>
#include <__config>
#include <__format/format_error.h>
#include <__format/format_fwd.h>
diff --git a/include/__format/parser_std_format_spec.h b/include/__format/parser_std_format_spec.h
index ca4eae1..57f4e46 100644
--- a/include/__format/parser_std_format_spec.h
+++ b/include/__format/parser_std_format_spec.h
@@ -12,8 +12,8 @@
#include <__algorithm/find_if.h>
#include <__algorithm/min.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__format/format_arg.h>
#include <__format/format_error.h>
#include <__format/format_string.h>
diff --git a/include/__functional/function.h b/include/__functional/function.h
index 1709876..4698c8c 100644
--- a/include/__functional/function.h
+++ b/include/__functional/function.h
@@ -10,8 +10,8 @@
#ifndef _LIBCPP___FUNCTIONAL_FUNCTION_H
#define _LIBCPP___FUNCTIONAL_FUNCTION_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__functional/binary_function.h>
#include <__functional/invoke.h>
#include <__functional/unary_function.h>
diff --git a/include/__hash_table b/include/__hash_table
index 6b1f65c..43c15d5 100644
--- a/include/__hash_table
+++ b/include/__hash_table
@@ -12,6 +12,7 @@
#include <__algorithm/max.h>
#include <__algorithm/min.h>
+#include <__assert>
#include <__bits> // __libcpp_clz
#include <__config>
#include <__debug>
diff --git a/include/__iterator/advance.h b/include/__iterator/advance.h
index 7b07951..da6bf05 100644
--- a/include/__iterator/advance.h
+++ b/include/__iterator/advance.h
@@ -10,8 +10,8 @@
#ifndef _LIBCPP___ITERATOR_ADVANCE_H
#define _LIBCPP___ITERATOR_ADVANCE_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
#include <__iterator/iterator_traits.h>
diff --git a/include/__iterator/common_iterator.h b/include/__iterator/common_iterator.h
index ad74dbd..505e4f1 100644
--- a/include/__iterator/common_iterator.h
+++ b/include/__iterator/common_iterator.h
@@ -10,8 +10,8 @@
#ifndef _LIBCPP___ITERATOR_COMMON_ITERATOR_H
#define _LIBCPP___ITERATOR_COMMON_ITERATOR_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
#include <__iterator/iter_move.h>
diff --git a/include/__iterator/counted_iterator.h b/include/__iterator/counted_iterator.h
index c67743f..826d5de 100644
--- a/include/__iterator/counted_iterator.h
+++ b/include/__iterator/counted_iterator.h
@@ -9,8 +9,8 @@
#ifndef _LIBCPP___ITERATOR_COUNTED_ITERATOR_H
#define _LIBCPP___ITERATOR_COUNTED_ITERATOR_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/concepts.h>
#include <__iterator/default_sentinel.h>
#include <__iterator/incrementable_traits.h>
diff --git a/include/__iterator/next.h b/include/__iterator/next.h
index 9f104bc..fae5989 100644
--- a/include/__iterator/next.h
+++ b/include/__iterator/next.h
@@ -10,8 +10,8 @@
#ifndef _LIBCPP___ITERATOR_NEXT_H
#define _LIBCPP___ITERATOR_NEXT_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/advance.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
diff --git a/include/__iterator/prev.h b/include/__iterator/prev.h
index 9779a8d..5839621 100644
--- a/include/__iterator/prev.h
+++ b/include/__iterator/prev.h
@@ -10,8 +10,8 @@
#ifndef _LIBCPP___ITERATOR_PREV_H
#define _LIBCPP___ITERATOR_PREV_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/advance.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
diff --git a/include/__memory/construct_at.h b/include/__memory/construct_at.h
index d0328f8..8a7bf40 100644
--- a/include/__memory/construct_at.h
+++ b/include/__memory/construct_at.h
@@ -10,8 +10,8 @@
#ifndef _LIBCPP___MEMORY_CONSTRUCT_AT_H
#define _LIBCPP___MEMORY_CONSTRUCT_AT_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/access.h>
#include <__memory/addressof.h>
#include <__memory/voidify.h>
diff --git a/include/__node_handle b/include/__node_handle
index fc35d0f..71309be 100644
--- a/include/__node_handle
+++ b/include/__node_handle
@@ -58,8 +58,8 @@
*/
+#include <__assert>
#include <__config>
-#include <__debug>
#include <memory>
#include <optional>
diff --git a/include/__numeric/gcd_lcm.h b/include/__numeric/gcd_lcm.h
index 34c0e53..9a53a00 100644
--- a/include/__numeric/gcd_lcm.h
+++ b/include/__numeric/gcd_lcm.h
@@ -10,8 +10,8 @@
#ifndef _LIBCPP___NUMERIC_GCD_LCM_H
#define _LIBCPP___NUMERIC_GCD_LCM_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <limits>
#include <type_traits>
diff --git a/include/__ranges/drop_view.h b/include/__ranges/drop_view.h
index 3fdf577..079a74d 100644
--- a/include/__ranges/drop_view.h
+++ b/include/__ranges/drop_view.h
@@ -9,8 +9,8 @@
#ifndef _LIBCPP___RANGES_DROP_VIEW_H
#define _LIBCPP___RANGES_DROP_VIEW_H
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/next.h>
diff --git a/include/__ranges/iota_view.h b/include/__ranges/iota_view.h
index 389034e..b7c099e 100644
--- a/include/__ranges/iota_view.h
+++ b/include/__ranges/iota_view.h
@@ -9,6 +9,7 @@
#ifndef _LIBCPP___RANGES_IOTA_VIEW_H
#define _LIBCPP___RANGES_IOTA_VIEW_H
+#include <__assert>
#include <__compare/three_way_comparable.h>
#include <__concepts/arithmetic.h>
#include <__concepts/constructible.h>
@@ -20,7 +21,6 @@
#include <__concepts/semiregular.h>
#include <__concepts/totally_ordered.h>
#include <__config>
-#include <__debug>
#include <__functional/ranges_operations.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
diff --git a/include/__ranges/subrange.h b/include/__ranges/subrange.h
index 57f0461..c54f771 100644
--- a/include/__ranges/subrange.h
+++ b/include/__ranges/subrange.h
@@ -9,13 +9,13 @@
#ifndef _LIBCPP___RANGES_SUBRANGE_H
#define _LIBCPP___RANGES_SUBRANGE_H
+#include <__assert>
#include <__concepts/constructible.h>
#include <__concepts/convertible_to.h>
#include <__concepts/copyable.h>
#include <__concepts/derived_from.h>
#include <__concepts/different_from.h>
#include <__config>
-#include <__debug>
#include <__iterator/advance.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
diff --git a/include/__ranges/view_interface.h b/include/__ranges/view_interface.h
index b0794b0..eecc475 100644
--- a/include/__ranges/view_interface.h
+++ b/include/__ranges/view_interface.h
@@ -9,10 +9,10 @@
#ifndef _LIBCPP___RANGES_VIEW_INTERFACE_H
#define _LIBCPP___RANGES_VIEW_INTERFACE_H
+#include <__assert>
#include <__concepts/derived_from.h>
#include <__concepts/same_as.h>
#include <__config>
-#include <__debug>
#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/prev.h>
diff --git a/include/__string b/include/__string
index 60a67d4..26aa619 100644
--- a/include/__string
+++ b/include/__string
@@ -17,7 +17,9 @@
#include <__algorithm/find_end.h>
#include <__algorithm/find_first_of.h>
#include <__algorithm/min.h>
+#include <__assert>
#include <__config>
+#include <__debug>
#include <__functional/hash.h> // for __murmur2_or_cityhash
#include <__iterator/iterator_traits.h>
#include <cstdint> // for uint_least16_t
@@ -30,8 +32,6 @@
# include <cwchar> // for wmemcpy
#endif
-#include <__debug>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
diff --git a/include/array b/include/array
index e55ee43..314d249 100644
--- a/include/array
+++ b/include/array
@@ -112,8 +112,8 @@
#include <__algorithm/fill_n.h>
#include <__algorithm/lexicographical_compare.h>
#include <__algorithm/swap_ranges.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__tuple>
#include <__utility/unreachable.h>
#include <iterator>
diff --git a/include/bit b/include/bit
index 16c7987..7f9318e 100644
--- a/include/bit
+++ b/include/bit
@@ -61,11 +61,11 @@
*/
+#include <__assert>
#include <__bit/bit_cast.h>
#include <__bit/byteswap.h>
#include <__bits> // __libcpp_clz
#include <__config>
-#include <__debug>
#include <limits>
#include <type_traits>
#include <version>
diff --git a/include/charconv b/include/charconv
index 8a953b0..86cbbd8 100644
--- a/include/charconv
+++ b/include/charconv
@@ -77,6 +77,7 @@
*/
+#include <__assert>
#include <__availability>
#include <__bits>
#include <__charconv/chars_format.h>
diff --git a/include/deque b/include/deque
index fc96475..b0fd148 100644
--- a/include/deque
+++ b/include/deque
@@ -169,8 +169,8 @@
#include <__algorithm/remove.h>
#include <__algorithm/remove_if.h>
#include <__algorithm/unwrap_iter.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/iterator_traits.h>
#include <__split_buffer>
#include <__utility/forward.h>
diff --git a/include/experimental/coroutine b/include/experimental/coroutine
index d14bd26..5a3a095 100644
--- a/include/experimental/coroutine
+++ b/include/experimental/coroutine
@@ -45,7 +45,7 @@
*/
-#include <__debug>
+#include <__assert>
#include <cstddef>
#include <experimental/__config>
#include <functional>
diff --git a/include/experimental/memory_resource b/include/experimental/memory_resource
index da3e103..098e25f 100644
--- a/include/experimental/memory_resource
+++ b/include/experimental/memory_resource
@@ -64,7 +64,7 @@
*/
-#include <__debug>
+#include <__assert>
#include <__tuple>
#include <cstddef>
#include <cstdlib>
diff --git a/include/fstream b/include/fstream
index d7d8fb1..80bda63 100644
--- a/include/fstream
+++ b/include/fstream
@@ -180,9 +180,9 @@
*/
#include <__algorithm/max.h>
+#include <__assert>
#include <__availability>
#include <__config>
-#include <__debug>
#include <__locale>
#include <__utility/unreachable.h>
#include <cstdio>
diff --git a/include/future b/include/future
index d49bc80..00f5a68 100644
--- a/include/future
+++ b/include/future
@@ -361,9 +361,9 @@
*/
+#include <__assert>
#include <__availability>
#include <__config>
-#include <__debug>
#include <__memory/allocator_arg_t.h>
#include <__memory/uses_allocator.h>
#include <__utility/auto_cast.h>
diff --git a/include/list b/include/list
index c643cb5..ac2e466 100644
--- a/include/list
+++ b/include/list
@@ -184,6 +184,7 @@
#include <__algorithm/equal.h>
#include <__algorithm/lexicographical_compare.h>
#include <__algorithm/min.h>
+#include <__assert>
#include <__config>
#include <__debug>
#include <__utility/forward.h>
diff --git a/include/locale b/include/locale
index fa82d44..fd605e3 100644
--- a/include/locale
+++ b/include/locale
@@ -192,6 +192,7 @@
#include <__algorithm/max.h>
#include <__algorithm/reverse.h>
#include <__algorithm/unwrap_iter.h>
+#include <__assert>
#include <__config>
#include <__debug>
#include <__locale>
diff --git a/include/map b/include/map
index a68c6d1..551edc5 100644
--- a/include/map
+++ b/include/map
@@ -530,8 +530,8 @@
#include <__algorithm/equal.h>
#include <__algorithm/lexicographical_compare.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__functional/is_transparent.h>
#include <__iterator/iterator_traits.h>
#include <__node_handle>
diff --git a/include/module.modulemap b/include/module.modulemap
index 95ff1ec..a444939 100644
--- a/include/module.modulemap
+++ b/include/module.modulemap
@@ -989,6 +989,7 @@
// __config not modularised due to a bug in Clang
// FIXME: These should be private.
+ module __assert { header "__assert" export * }
module __availability { private header "__availability" export * }
module __bit_reference { private header "__bit_reference" export * }
module __bits { private header "__bits" export * }
diff --git a/include/optional b/include/optional
index aa299f7..b20081d 100644
--- a/include/optional
+++ b/include/optional
@@ -158,10 +158,10 @@
*/
+#include <__assert>
#include <__availability>
#include <__concepts/invocable.h>
#include <__config>
-#include <__debug>
#include <compare>
#include <functional>
#include <initializer_list>
diff --git a/include/regex b/include/regex
index dadd7b9..68922f6 100644
--- a/include/regex
+++ b/include/regex
@@ -763,8 +763,8 @@
*/
#include <__algorithm/find.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__iterator/wrap_iter.h>
#include <__locale>
#include <compare>
diff --git a/include/set b/include/set
index b346e57..be117d0 100644
--- a/include/set
+++ b/include/set
@@ -473,8 +473,8 @@
#include <__algorithm/equal.h>
#include <__algorithm/lexicographical_compare.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__functional/is_transparent.h>
#include <__iterator/iterator_traits.h>
#include <__node_handle>
diff --git a/include/span b/include/span
index 6689740..46df783 100644
--- a/include/span
+++ b/include/span
@@ -127,6 +127,7 @@
*/
+#include <__assert>
#include <__config>
#include <__debug>
#include <__iterator/concepts.h>
diff --git a/include/string b/include/string
index 3e7f2e9..892df77 100644
--- a/include/string
+++ b/include/string
@@ -522,6 +522,7 @@
#include <__algorithm/min.h>
#include <__algorithm/remove.h>
#include <__algorithm/remove_if.h>
+#include <__assert>
#include <__config>
#include <__debug>
#include <__ios/fpos.h>
diff --git a/include/string_view b/include/string_view
index a5256fb..dd9239a 100644
--- a/include/string_view
+++ b/include/string_view
@@ -196,8 +196,8 @@
*/
#include <__algorithm/min.h>
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__ranges/concepts.h>
#include <__ranges/data.h>
#include <__ranges/enable_borrowed_range.h>
diff --git a/include/thread b/include/thread
index 5681f9d..5aa698e 100644
--- a/include/thread
+++ b/include/thread
@@ -82,8 +82,8 @@
*/
+#include <__assert>
#include <__config>
-#include <__debug>
#include <__mutex_base>
#include <__thread/poll_with_backoff.h>
#include <__thread/timed_backoff_policy.h>
diff --git a/include/unordered_map b/include/unordered_map
index 34c3d18..c854548 100644
--- a/include/unordered_map
+++ b/include/unordered_map
@@ -515,6 +515,7 @@
*/
#include <__algorithm/is_permutation.h>
+#include <__assert>
#include <__config>
#include <__debug>
#include <__functional/is_transparent.h>
diff --git a/include/unordered_set b/include/unordered_set
index bf972be..2f902cc 100644
--- a/include/unordered_set
+++ b/include/unordered_set
@@ -460,6 +460,7 @@
*/
#include <__algorithm/is_permutation.h>
+#include <__assert>
#include <__config>
#include <__debug>
#include <__functional/is_transparent.h>
diff --git a/include/vector b/include/vector
index 26683ae..57d3506 100644
--- a/include/vector
+++ b/include/vector
@@ -279,6 +279,7 @@
#include <__algorithm/remove_if.h>
#include <__algorithm/rotate.h>
#include <__algorithm/unwrap_iter.h>
+#include <__assert>
#include <__bit_reference>
#include <__config>
#include <__debug>