[libc++] Ensure that all public C++ headers include <__assert>
This patch changes the requirement for getting the declaration of the
assertion handler from including <__assert> to including any public
C++ header of the library. Note that C compatibility headers are
excluded because we don't implement all the C headers ourselves --
some of them are taken straight from the C library, like assert.h.
It also adds a generated test to check it. Furthermore, this new
generated test is designed in a way that will make it possible to
replace almost all the existing test-generation scripts with this
system in upcoming patches.
Differential Revision: https://reviews.llvm.org/D122506
GitOrigin-RevId: 385cc25a531a72c393cee44689e2c3194615bcec
diff --git a/docs/UsingLibcxx.rst b/docs/UsingLibcxx.rst
index 3eab44a..0d7e3a9 100644
--- a/docs/UsingLibcxx.rst
+++ b/docs/UsingLibcxx.rst
@@ -169,7 +169,7 @@
.. code-block:: cpp
// In HelloWorldHandler.cpp
- #include <__assert> // must include <__assert> before defining the handler
+ #include <version> // must include any libc++ header before defining the handler (C compatibility headers excluded)
void std::__libcpp_assertion_handler(char const* file, int line, char const* expression, char const* message) {
std::printf("Assertion %s failed at %s:%d, more info: %s", expression, file, line, message);
diff --git a/include/algorithm b/include/algorithm
index 51a1781..c199c5a 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -733,6 +733,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__bits>
#include <__config>
#include <__debug>
diff --git a/include/any b/include/any
index fc1641f..bd0ea56 100644
--- a/include/any
+++ b/include/any
@@ -80,6 +80,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <__utility/forward.h>
diff --git a/include/array b/include/array
index 0b36608..786dc75 100644
--- a/include/array
+++ b/include/array
@@ -112,7 +112,7 @@
#include <__algorithm/fill_n.h>
#include <__algorithm/lexicographical_compare.h>
#include <__algorithm/swap_ranges.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__tuple>
#include <__utility/integer_sequence.h>
diff --git a/include/atomic b/include/atomic
index dfa01bf..b5c6e51 100644
--- a/include/atomic
+++ b/include/atomic
@@ -518,6 +518,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__chrono/duration.h>
#include <__config>
diff --git a/include/barrier b/include/barrier
index 0382f2f..6f8a1f9 100644
--- a/include/barrier
+++ b/include/barrier
@@ -45,6 +45,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <__thread/timed_backoff_policy.h>
diff --git a/include/bit b/include/bit
index aaefd8a..b73c4b4 100644
--- a/include/bit
+++ b/include/bit
@@ -61,7 +61,7 @@
*/
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__bit/bit_cast.h>
#include <__bit/byteswap.h>
#include <__bits> // __libcpp_clz
diff --git a/include/bitset b/include/bitset
index 07c9494..28862d8 100644
--- a/include/bitset
+++ b/include/bitset
@@ -113,6 +113,7 @@
*/
#include <__algorithm/fill.h>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__bit_reference>
#include <__config>
#include <__functional/unary_function.h>
diff --git a/include/cassert b/include/cassert
index 3c5bb7b..28fc0b1 100644
--- a/include/cassert
+++ b/include/cassert
@@ -16,6 +16,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <assert.h>
diff --git a/include/ccomplex b/include/ccomplex
index f1037f2..cf05c7a 100644
--- a/include/ccomplex
+++ b/include/ccomplex
@@ -17,12 +17,11 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <complex>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
-// hh 080623 Created
-
#endif // _LIBCPP_CCOMPLEX
diff --git a/include/cctype b/include/cctype
index fc770cf..248f8d9 100644
--- a/include/cctype
+++ b/include/cctype
@@ -34,6 +34,7 @@
} // std
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <ctype.h>
diff --git a/include/cerrno b/include/cerrno
index 9946c85..e9eacd3 100644
--- a/include/cerrno
+++ b/include/cerrno
@@ -22,6 +22,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <errno.h>
diff --git a/include/cfenv b/include/cfenv
index e1aae2f..e42b466 100644
--- a/include/cfenv
+++ b/include/cfenv
@@ -52,6 +52,7 @@
} // std
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <fenv.h>
diff --git a/include/cfloat b/include/cfloat
index ff806ce..36a7c51 100644
--- a/include/cfloat
+++ b/include/cfloat
@@ -69,6 +69,7 @@
LDBL_TRUE_MIN // C11
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <float.h>
diff --git a/include/charconv b/include/charconv
index 3b766e6..ca717dc 100644
--- a/include/charconv
+++ b/include/charconv
@@ -77,7 +77,7 @@
*/
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__bits>
#include <__charconv/chars_format.h>
diff --git a/include/chrono b/include/chrono
index 63558ad..c6efd33 100644
--- a/include/chrono
+++ b/include/chrono
@@ -694,6 +694,7 @@
} // std
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__chrono/calendar.h>
#include <__chrono/convert_to_timespec.h>
#include <__chrono/duration.h>
diff --git a/include/cinttypes b/include/cinttypes
index 0674384..a4cfe96 100644
--- a/include/cinttypes
+++ b/include/cinttypes
@@ -234,6 +234,7 @@
} // std
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cstdint>
#include <inttypes.h>
diff --git a/include/ciso646 b/include/ciso646
index 1d859f0..e0cd722 100644
--- a/include/ciso646
+++ b/include/ciso646
@@ -15,6 +15,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/include/climits b/include/climits
index c365ca7..16800a6 100644
--- a/include/climits
+++ b/include/climits
@@ -37,6 +37,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <limits.h>
diff --git a/include/clocale b/include/clocale
index 1c1f244..8926042 100644
--- a/include/clocale
+++ b/include/clocale
@@ -34,6 +34,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <locale.h>
diff --git a/include/cmath b/include/cmath
index be5cbe3..2d22151 100644
--- a/include/cmath
+++ b/include/cmath
@@ -304,6 +304,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <math.h>
#include <type_traits>
diff --git a/include/codecvt b/include/codecvt
index b9b38b3..d3a9486 100644
--- a/include/codecvt
+++ b/include/codecvt
@@ -54,6 +54,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__locale>
#include <version>
diff --git a/include/compare b/include/compare
index 6f620e4..6aa1abe 100644
--- a/include/compare
+++ b/include/compare
@@ -140,6 +140,7 @@
}
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__compare/common_comparison_category.h>
#include <__compare/compare_partial_order_fallback.h>
#include <__compare/compare_strong_order_fallback.h>
diff --git a/include/complex b/include/complex
index 8384ed8..87a4e58 100644
--- a/include/complex
+++ b/include/complex
@@ -231,6 +231,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cmath>
#include <iosfwd>
diff --git a/include/concepts b/include/concepts
index 99dbcf4..301256c 100644
--- a/include/concepts
+++ b/include/concepts
@@ -129,6 +129,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__concepts/arithmetic.h>
#include <__concepts/assignable.h>
#include <__concepts/boolean_testable.h>
diff --git a/include/condition_variable b/include/condition_variable
index 6da7246..dfcb716 100644
--- a/include/condition_variable
+++ b/include/condition_variable
@@ -106,6 +106,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__mutex_base>
#include <memory>
diff --git a/include/coroutine b/include/coroutine
index 478f472..11b2863 100644
--- a/include/coroutine
+++ b/include/coroutine
@@ -38,6 +38,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__coroutine/coroutine_handle.h>
#include <__coroutine/coroutine_traits.h>
diff --git a/include/csetjmp b/include/csetjmp
index 76cbaab..4f40bcb 100644
--- a/include/csetjmp
+++ b/include/csetjmp
@@ -30,6 +30,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <setjmp.h>
diff --git a/include/csignal b/include/csignal
index 19091cf..81ca890 100644
--- a/include/csignal
+++ b/include/csignal
@@ -39,6 +39,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <signal.h>
diff --git a/include/cstdarg b/include/cstdarg
index 7dd9068..f36ade2 100644
--- a/include/cstdarg
+++ b/include/cstdarg
@@ -31,6 +31,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <stdarg.h>
diff --git a/include/cstdbool b/include/cstdbool
index ef731c0..ce60803 100644
--- a/include/cstdbool
+++ b/include/cstdbool
@@ -19,6 +19,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/include/cstddef b/include/cstddef
index 57cecc7..2a8b686 100644
--- a/include/cstddef
+++ b/include/cstddef
@@ -33,6 +33,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <stddef.h>
#include <version>
diff --git a/include/cstdint b/include/cstdint
index cac715b..83cda94 100644
--- a/include/cstdint
+++ b/include/cstdint
@@ -140,6 +140,7 @@
} // std
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <stdint.h>
diff --git a/include/cstdio b/include/cstdio
index d5b748d..d191086 100644
--- a/include/cstdio
+++ b/include/cstdio
@@ -95,6 +95,7 @@
} // std
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <stdio.h>
diff --git a/include/cstdlib b/include/cstdlib
index 9fad7e1..457c31f 100644
--- a/include/cstdlib
+++ b/include/cstdlib
@@ -81,6 +81,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <stdlib.h>
diff --git a/include/cstring b/include/cstring
index acf1c4d..37c92e1 100644
--- a/include/cstring
+++ b/include/cstring
@@ -56,6 +56,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <string.h>
diff --git a/include/ctgmath b/include/ctgmath
index 6237979..bfcf2f9 100644
--- a/include/ctgmath
+++ b/include/ctgmath
@@ -18,6 +18,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <ccomplex>
#include <cmath>
diff --git a/include/ctime b/include/ctime
index 58856e8..0c6e4df 100644
--- a/include/ctime
+++ b/include/ctime
@@ -45,6 +45,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <time.h>
diff --git a/include/cuchar b/include/cuchar
index fec1492..a4ed585 100644
--- a/include/cuchar
+++ b/include/cuchar
@@ -34,6 +34,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <uchar.h>
diff --git a/include/cwchar b/include/cwchar
index c4d8521..5c69ab2 100644
--- a/include/cwchar
+++ b/include/cwchar
@@ -102,6 +102,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cwctype>
#include <wchar.h>
diff --git a/include/cwctype b/include/cwctype
index b4434f6..429b00c 100644
--- a/include/cwctype
+++ b/include/cwctype
@@ -49,6 +49,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cctype>
#include <wctype.h>
diff --git a/include/deque b/include/deque
index 184bae0..4b78d77 100644
--- a/include/deque
+++ b/include/deque
@@ -169,7 +169,7 @@
#include <__algorithm/remove.h>
#include <__algorithm/remove_if.h>
#include <__algorithm/unwrap_iter.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__split_buffer>
diff --git a/include/exception b/include/exception
index a60c8e6..412e02a 100644
--- a/include/exception
+++ b/include/exception
@@ -76,6 +76,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <__memory/addressof.h>
diff --git a/include/execution b/include/execution
index f469332..0402970 100644
--- a/include/execution
+++ b/include/execution
@@ -10,6 +10,7 @@
#ifndef _LIBCPP_EXECUTION
#define _LIBCPP_EXECUTION
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <version>
diff --git a/include/experimental/algorithm b/include/experimental/algorithm
index b9405bf..e0ca3c7 100644
--- a/include/experimental/algorithm
+++ b/include/experimental/algorithm
@@ -31,6 +31,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__debug>
#include <algorithm>
#include <experimental/__config>
diff --git a/include/experimental/coroutine b/include/experimental/coroutine
index 837ab10..e94450b 100644
--- a/include/experimental/coroutine
+++ b/include/experimental/coroutine
@@ -45,7 +45,7 @@
*/
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <cstddef>
#include <experimental/__config>
#include <functional>
diff --git a/include/experimental/deque b/include/experimental/deque
index 1809991..3e3f909 100644
--- a/include/experimental/deque
+++ b/include/experimental/deque
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_DEQUE
#define _LIBCPP_EXPERIMENTAL_DEQUE
+
/*
experimental/deque synopsis
@@ -28,6 +29,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <deque>
#include <experimental/__config>
#include <experimental/memory_resource>
diff --git a/include/experimental/forward_list b/include/experimental/forward_list
index 675ae06..4b102c5 100644
--- a/include/experimental/forward_list
+++ b/include/experimental/forward_list
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_FORWARD_LIST
#define _LIBCPP_EXPERIMENTAL_FORWARD_LIST
+
/*
experimental/forward_list synopsis
@@ -28,6 +29,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <forward_list>
diff --git a/include/experimental/functional b/include/experimental/functional
index 1291894..0da5fce 100644
--- a/include/experimental/functional
+++ b/include/experimental/functional
@@ -60,6 +60,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__debug>
#include <__memory/uses_allocator.h>
#include <array>
diff --git a/include/experimental/iterator b/include/experimental/iterator
index 137b206..79c594f 100644
--- a/include/experimental/iterator
+++ b/include/experimental/iterator
@@ -52,6 +52,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__memory/addressof.h>
#include <__utility/forward.h>
#include <__utility/move.h>
diff --git a/include/experimental/list b/include/experimental/list
index d15d816..c848057 100644
--- a/include/experimental/list
+++ b/include/experimental/list
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_LIST
#define _LIBCPP_EXPERIMENTAL_LIST
+
/*
experimental/list synopsis
@@ -28,6 +29,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <list>
diff --git a/include/experimental/map b/include/experimental/map
index 25bc56c..3dee7f7 100644
--- a/include/experimental/map
+++ b/include/experimental/map
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_MAP
#define _LIBCPP_EXPERIMENTAL_MAP
+
/*
experimental/map synopsis
@@ -33,6 +34,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <map>
diff --git a/include/experimental/memory_resource b/include/experimental/memory_resource
index 16c7d8d..f7b19aa 100644
--- a/include/experimental/memory_resource
+++ b/include/experimental/memory_resource
@@ -64,7 +64,7 @@
*/
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__tuple>
#include <__utility/move.h>
#include <cstddef>
diff --git a/include/experimental/propagate_const b/include/experimental/propagate_const
index e622422..7c9b783 100644
--- a/include/experimental/propagate_const
+++ b/include/experimental/propagate_const
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST
#define _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST
+
/*
propagate_const synopsis
@@ -106,6 +107,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__utility/move.h>
#include <__utility/swap.h>
#include <experimental/__config>
diff --git a/include/experimental/regex b/include/experimental/regex
index f108d2e..4dc2bba 100644
--- a/include/experimental/regex
+++ b/include/experimental/regex
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_REGEX
#define _LIBCPP_EXPERIMENTAL_REGEX
+
/*
experimental/regex synopsis
@@ -35,6 +36,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <experimental/string>
diff --git a/include/experimental/set b/include/experimental/set
index 208952c..e2e75e3 100644
--- a/include/experimental/set
+++ b/include/experimental/set
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_SET
#define _LIBCPP_EXPERIMENTAL_SET
+
/*
experimental/set synopsis
@@ -33,6 +34,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <set>
diff --git a/include/experimental/simd b/include/experimental/simd
index 93d39c8..7fa185f 100644
--- a/include/experimental/simd
+++ b/include/experimental/simd
@@ -649,6 +649,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <array>
#include <cstddef>
#include <experimental/__config>
diff --git a/include/experimental/string b/include/experimental/string
index aab9167..c795d68 100644
--- a/include/experimental/string
+++ b/include/experimental/string
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_STRING
#define _LIBCPP_EXPERIMENTAL_STRING
+
/*
experimental/string synopsis
@@ -37,6 +38,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <string>
diff --git a/include/experimental/type_traits b/include/experimental/type_traits
index 707cbde..dd4c539 100644
--- a/include/experimental/type_traits
+++ b/include/experimental/type_traits
@@ -68,6 +68,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#if _LIBCPP_STD_VER > 11
diff --git a/include/experimental/unordered_map b/include/experimental/unordered_map
index 069ba20..71ce440 100644
--- a/include/experimental/unordered_map
+++ b/include/experimental/unordered_map
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_UNORDERED_MAP
#define _LIBCPP_EXPERIMENTAL_UNORDERED_MAP
+
/*
experimental/unordered_map synopsis
@@ -39,6 +40,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <unordered_map>
diff --git a/include/experimental/unordered_set b/include/experimental/unordered_set
index cac6c76..509f3ec 100644
--- a/include/experimental/unordered_set
+++ b/include/experimental/unordered_set
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_UNORDERED_SET
#define _LIBCPP_EXPERIMENTAL_UNORDERED_SET
+
/*
experimental/unordered_set synopsis
@@ -33,6 +34,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <unordered_set>
diff --git a/include/experimental/utility b/include/experimental/utility
index 21650a8..576b8be 100644
--- a/include/experimental/utility
+++ b/include/experimental/utility
@@ -30,6 +30,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <utility>
diff --git a/include/experimental/vector b/include/experimental/vector
index 1eb7927..97c51c8 100644
--- a/include/experimental/vector
+++ b/include/experimental/vector
@@ -9,6 +9,7 @@
#ifndef _LIBCPP_EXPERIMENTAL_VECTOR
#define _LIBCPP_EXPERIMENTAL_VECTOR
+
/*
experimental/vector synopsis
@@ -28,6 +29,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <experimental/__config>
#include <experimental/memory_resource>
#include <vector>
diff --git a/include/ext/hash_map b/include/ext/hash_map
index 1816626..92572c0 100644
--- a/include/ext/hash_map
+++ b/include/ext/hash_map
@@ -201,9 +201,10 @@
*/
-#include <__algorithm/is_permutation.h>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__hash_table>
+#include <algorithm>
#include <ext/__hash>
#include <functional>
#include <stdexcept>
diff --git a/include/ext/hash_set b/include/ext/hash_set
index cbd621b..eb61939 100644
--- a/include/ext/hash_set
+++ b/include/ext/hash_set
@@ -192,9 +192,10 @@
*/
-#include <__algorithm/is_permutation.h>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__hash_table>
+#include <algorithm>
#include <ext/__hash>
#include <functional>
diff --git a/include/filesystem b/include/filesystem
index afb75df..c23cac9 100644
--- a/include/filesystem
+++ b/include/filesystem
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_FILESYSTEM
#define _LIBCPP_FILESYSTEM
+
/*
filesystem synopsis
@@ -238,6 +239,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__filesystem/copy_options.h>
#include <__filesystem/directory_entry.h>
diff --git a/include/format b/include/format
index 5ff62c3..6cefab4 100644
--- a/include/format
+++ b/include/format
@@ -117,6 +117,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
// Make sure all feature-test macros are available.
#include <version>
// Enable the contents of the header only when libc++ was built with LIBCXX_ENABLE_INCOMPLETE_FEATURES.
diff --git a/include/forward_list b/include/forward_list
index 4b3f4e2..23c1229 100644
--- a/include/forward_list
+++ b/include/forward_list
@@ -182,6 +182,7 @@
#include <__algorithm/comp.h>
#include <__algorithm/lexicographical_compare.h>
#include <__algorithm/min.h>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__utility/forward.h>
#include <initializer_list>
diff --git a/include/fstream b/include/fstream
index 2f1cd32..907c59e 100644
--- a/include/fstream
+++ b/include/fstream
@@ -180,7 +180,7 @@
*/
#include <__algorithm/max.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <__locale>
diff --git a/include/functional b/include/functional
index d097861..7430551 100644
--- a/include/functional
+++ b/include/functional
@@ -491,6 +491,7 @@
*/
#include <__algorithm/search.h>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__compare/compare_three_way.h>
#include <__config>
#include <__debug>
diff --git a/include/future b/include/future
index 162d400..b397477 100644
--- a/include/future
+++ b/include/future
@@ -361,7 +361,7 @@
*/
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__chrono/duration.h>
#include <__chrono/time_point.h>
diff --git a/include/initializer_list b/include/initializer_list
index e61318e..02a8ec5 100644
--- a/include/initializer_list
+++ b/include/initializer_list
@@ -42,6 +42,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cstddef>
diff --git a/include/iomanip b/include/iomanip
index c4d8351..69b55be 100644
--- a/include/iomanip
+++ b/include/iomanip
@@ -42,6 +42,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__string>
#include <istream>
diff --git a/include/ios b/include/ios
index 15053e5..a790ba5 100644
--- a/include/ios
+++ b/include/ios
@@ -210,6 +210,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__ios/fpos.h>
#include <__locale>
diff --git a/include/iosfwd b/include/iosfwd
index 263a667..6cb5586 100644
--- a/include/iosfwd
+++ b/include/iosfwd
@@ -94,6 +94,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__mbstate_t.h>
#include <version>
diff --git a/include/iostream b/include/iostream
index 10d17d6..b5aef3e 100644
--- a/include/iostream
+++ b/include/iostream
@@ -33,6 +33,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <ios>
#include <istream>
diff --git a/include/istream b/include/istream
index 8259c52..201339f 100644
--- a/include/istream
+++ b/include/istream
@@ -158,6 +158,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__utility/forward.h>
#include <ostream>
diff --git a/include/iterator b/include/iterator
index 8ba4d0c..4060c2d 100644
--- a/include/iterator
+++ b/include/iterator
@@ -634,6 +634,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__debug>
#include <__iterator/access.h>
diff --git a/include/latch b/include/latch
index 7df7fda..d6cb476 100644
--- a/include/latch
+++ b/include/latch
@@ -40,6 +40,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <atomic>
diff --git a/include/limits b/include/limits
index 5afef4b..35e4d85 100644
--- a/include/limits
+++ b/include/limits
@@ -101,6 +101,8 @@
} // std
*/
+
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <type_traits>
diff --git a/include/list b/include/list
index 31cacbc..c3337d4 100644
--- a/include/list
+++ b/include/list
@@ -184,7 +184,7 @@
#include <__algorithm/equal.h>
#include <__algorithm/lexicographical_compare.h>
#include <__algorithm/min.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__debug>
#include <__utility/forward.h>
diff --git a/include/locale b/include/locale
index 067c146..8ff7567 100644
--- a/include/locale
+++ b/include/locale
@@ -192,7 +192,7 @@
#include <__algorithm/max.h>
#include <__algorithm/reverse.h>
#include <__algorithm/unwrap_iter.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__debug>
#include <__locale>
diff --git a/include/map b/include/map
index 8d26cdb..7371d51 100644
--- a/include/map
+++ b/include/map
@@ -530,7 +530,7 @@
#include <__algorithm/equal.h>
#include <__algorithm/lexicographical_compare.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__functional/is_transparent.h>
#include <__iterator/iterator_traits.h>
diff --git a/include/memory b/include/memory
index 1991e29..53172c5 100644
--- a/include/memory
+++ b/include/memory
@@ -804,6 +804,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__memory/addressof.h>
#include <__memory/allocation_guard.h>
diff --git a/include/mutex b/include/mutex
index 536cf9c..a94e3b7 100644
--- a/include/mutex
+++ b/include/mutex
@@ -186,6 +186,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__mutex_base>
#include <__threading_support>
diff --git a/include/new b/include/new
index 0d8d43e..e91a422 100644
--- a/include/new
+++ b/include/new
@@ -86,6 +86,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <cstddef>
diff --git a/include/numbers b/include/numbers
index 22b185a..3c8527d 100644
--- a/include/numbers
+++ b/include/numbers
@@ -58,6 +58,7 @@
}
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <concepts>
#include <type_traits>
diff --git a/include/numeric b/include/numeric
index c8c6bce..ef96336 100644
--- a/include/numeric
+++ b/include/numeric
@@ -144,6 +144,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cmath> // for isnormal
#include <functional>
diff --git a/include/optional b/include/optional
index 22b0cf1..8dc1a13 100644
--- a/include/optional
+++ b/include/optional
@@ -158,7 +158,7 @@
*/
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__concepts/invocable.h>
#include <__config>
diff --git a/include/ostream b/include/ostream
index 3587c35..702f505 100644
--- a/include/ostream
+++ b/include/ostream
@@ -134,6 +134,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <bitset>
#include <ios>
diff --git a/include/queue b/include/queue
index b8b7ec4..d15c141 100644
--- a/include/queue
+++ b/include/queue
@@ -220,6 +220,7 @@
#include <__algorithm/make_heap.h>
#include <__algorithm/pop_heap.h>
#include <__algorithm/push_heap.h>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__memory/uses_allocator.h>
diff --git a/include/random b/include/random
index 0323c44..a2e1719 100644
--- a/include/random
+++ b/include/random
@@ -1677,6 +1677,7 @@
} // std
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__random/bernoulli_distribution.h>
#include <__random/binomial_distribution.h>
diff --git a/include/ranges b/include/ranges
index b6c028d..5be1614 100644
--- a/include/ranges
+++ b/include/ranges
@@ -230,6 +230,7 @@
}
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__ranges/access.h>
#include <__ranges/all.h>
diff --git a/include/ratio b/include/ratio
index 07376bf..5d7af88 100644
--- a/include/ratio
+++ b/include/ratio
@@ -77,6 +77,7 @@
}
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <climits>
#include <cstdint>
diff --git a/include/regex b/include/regex
index 661a08b..456f34d 100644
--- a/include/regex
+++ b/include/regex
@@ -763,7 +763,7 @@
*/
#include <__algorithm/find.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__iterator/wrap_iter.h>
#include <__locale>
diff --git a/include/scoped_allocator b/include/scoped_allocator
index fe6d606..b505aad 100644
--- a/include/scoped_allocator
+++ b/include/scoped_allocator
@@ -109,6 +109,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__utility/forward.h>
#include <memory>
diff --git a/include/semaphore b/include/semaphore
index df7b0d9..b174eba 100644
--- a/include/semaphore
+++ b/include/semaphore
@@ -45,6 +45,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__chrono/time_point.h>
#include <__config>
diff --git a/include/set b/include/set
index 1ac86a1..a2d43cd 100644
--- a/include/set
+++ b/include/set
@@ -473,7 +473,7 @@
#include <__algorithm/equal.h>
#include <__algorithm/lexicographical_compare.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__functional/is_transparent.h>
#include <__iterator/iterator_traits.h>
diff --git a/include/shared_mutex b/include/shared_mutex
index 95aa378..68a2bba 100644
--- a/include/shared_mutex
+++ b/include/shared_mutex
@@ -122,6 +122,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <version>
diff --git a/include/span b/include/span
index adb7d00..b964665 100644
--- a/include/span
+++ b/include/span
@@ -127,7 +127,7 @@
*/
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__debug>
#include <__iterator/concepts.h>
diff --git a/include/sstream b/include/sstream
index ba6148b..4ab3af7 100644
--- a/include/sstream
+++ b/include/sstream
@@ -180,6 +180,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__utility/swap.h>
#include <istream>
diff --git a/include/stack b/include/stack
index 87d85c4..7405896 100644
--- a/include/stack
+++ b/include/stack
@@ -98,6 +98,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__memory/uses_allocator.h>
diff --git a/include/stdbool.h b/include/stdbool.h
index 369f8b3..0bc1aa8 100644
--- a/include/stdbool.h
+++ b/include/stdbool.h
@@ -9,7 +9,6 @@
#ifndef _LIBCPP_STDBOOL_H
#define _LIBCPP_STDBOOL_H
-
/*
stdbool.h synopsis
diff --git a/include/stdexcept b/include/stdexcept
index f6dcf5f..ee5a296 100644
--- a/include/stdexcept
+++ b/include/stdexcept
@@ -41,6 +41,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cstdlib>
#include <exception>
diff --git a/include/streambuf b/include/streambuf
index abcdfe2..d76f6d0 100644
--- a/include/streambuf
+++ b/include/streambuf
@@ -107,6 +107,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cstdint>
#include <ios>
diff --git a/include/string b/include/string
index c79c0ed..60b40c3 100644
--- a/include/string
+++ b/include/string
@@ -522,7 +522,7 @@
#include <__algorithm/min.h>
#include <__algorithm/remove.h>
#include <__algorithm/remove_if.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__debug>
#include <__ios/fpos.h>
diff --git a/include/string_view b/include/string_view
index 0b2456d..7c5d52b 100644
--- a/include/string_view
+++ b/include/string_view
@@ -11,7 +11,8 @@
#define _LIBCPP_STRING_VIEW
/*
-string_view synopsis
+
+ string_view synopsis
namespace std {
@@ -196,7 +197,7 @@
*/
#include <__algorithm/min.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__ranges/concepts.h>
#include <__ranges/data.h>
diff --git a/include/strstream b/include/strstream
index 1904bb7..9ffdd9f 100644
--- a/include/strstream
+++ b/include/strstream
@@ -129,6 +129,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <istream>
#include <ostream>
diff --git a/include/system_error b/include/system_error
index 48a6b2e..feffa2d 100644
--- a/include/system_error
+++ b/include/system_error
@@ -142,6 +142,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__errc>
#include <__functional/unary_function.h>
diff --git a/include/thread b/include/thread
index 5a8e830..540f591 100644
--- a/include/thread
+++ b/include/thread
@@ -82,7 +82,7 @@
*/
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__mutex_base>
#include <__thread/poll_with_backoff.h>
diff --git a/include/tuple b/include/tuple
index ea7245d..0a62578 100644
--- a/include/tuple
+++ b/include/tuple
@@ -165,6 +165,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__compare/common_comparison_category.h>
#include <__compare/synth_three_way.h>
#include <__config>
diff --git a/include/type_traits b/include/type_traits
index 0ecb0f9..952f578 100644
--- a/include/type_traits
+++ b/include/type_traits
@@ -416,6 +416,8 @@
}
*/
+
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cstddef>
#include <version>
diff --git a/include/typeindex b/include/typeindex
index f068039..0b61f28 100644
--- a/include/typeindex
+++ b/include/typeindex
@@ -44,6 +44,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__functional/unary_function.h>
#include <compare>
diff --git a/include/typeinfo b/include/typeinfo
index 3d23458..a0ac527 100644
--- a/include/typeinfo
+++ b/include/typeinfo
@@ -56,6 +56,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <cstddef>
diff --git a/include/unordered_map b/include/unordered_map
index c701e67..b7acfc3 100644
--- a/include/unordered_map
+++ b/include/unordered_map
@@ -515,7 +515,7 @@
*/
#include <__algorithm/is_permutation.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__debug>
#include <__functional/is_transparent.h>
diff --git a/include/unordered_set b/include/unordered_set
index 0dd53a2..f4ec9f5 100644
--- a/include/unordered_set
+++ b/include/unordered_set
@@ -460,7 +460,7 @@
*/
#include <__algorithm/is_permutation.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__debug>
#include <__functional/is_transparent.h>
diff --git a/include/utility b/include/utility
index ab19e2b..bcd4abf 100644
--- a/include/utility
+++ b/include/utility
@@ -220,8 +220,8 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
-#include <__debug>
#include <__tuple>
#include <__utility/as_const.h>
#include <__utility/auto_cast.h>
diff --git a/include/valarray b/include/valarray
index 8ceaafe..d79b0b2 100644
--- a/include/valarray
+++ b/include/valarray
@@ -348,6 +348,7 @@
#include <__algorithm/min.h>
#include <__algorithm/min_element.h>
#include <__algorithm/unwrap_iter.h>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <cmath>
#include <cstddef>
diff --git a/include/variant b/include/variant
index 3c68ab2..6012aaa 100644
--- a/include/variant
+++ b/include/variant
@@ -199,6 +199,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__availability>
#include <__config>
#include <__functional/hash.h>
diff --git a/include/vector b/include/vector
index ba4c1b4..064a99d 100644
--- a/include/vector
+++ b/include/vector
@@ -279,7 +279,7 @@
#include <__algorithm/remove_if.h>
#include <__algorithm/rotate.h>
#include <__algorithm/unwrap_iter.h>
-#include <__assert>
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__bit_reference>
#include <__config>
#include <__debug>
diff --git a/include/version b/include/version
index 1fbba7e..003a42c 100644
--- a/include/version
+++ b/include/version
@@ -193,6 +193,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/test/libcxx/assertions/assertions_disabled.pass.cpp b/test/libcxx/assertions/assertions_disabled.pass.cpp
index 52dd785..5ec5f12 100644
--- a/test/libcxx/assertions/assertions_disabled.pass.cpp
+++ b/test/libcxx/assertions/assertions_disabled.pass.cpp
@@ -12,7 +12,6 @@
// ADDITIONAL_COMPILE_FLAGS: -Wno-macro-redefined -D_LIBCPP_ENABLE_ASSERTIONS=0
-#include <__assert>
#include <cassert>
bool executed_condition = false;
diff --git a/test/libcxx/assertions/customize_handler.backdeployment.pass.cpp b/test/libcxx/assertions/customize_handler.backdeployment.pass.cpp
index 59b56d3..fda41a5 100644
--- a/test/libcxx/assertions/customize_handler.backdeployment.pass.cpp
+++ b/test/libcxx/assertions/customize_handler.backdeployment.pass.cpp
@@ -14,7 +14,6 @@
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_ASSERTIONS=1 -D_LIBCPP_AVAILABILITY_CUSTOM_ASSERTION_HANDLER_PROVIDED
-#include <__assert>
#include <cassert>
bool handler_called = false;
diff --git a/test/libcxx/assertions/customize_handler.pass.cpp b/test/libcxx/assertions/customize_handler.pass.cpp
index 2a0f26a..5d66141 100644
--- a/test/libcxx/assertions/customize_handler.pass.cpp
+++ b/test/libcxx/assertions/customize_handler.pass.cpp
@@ -14,7 +14,6 @@
// failures when back-deploying.
// UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11|12}}
-#include <__assert>
#include <cassert>
bool handler_called = false;
diff --git a/test/libcxx/assertions/debug_mode_compatibility.pass.cpp b/test/libcxx/assertions/debug_mode_compatibility.pass.cpp
index 61ebb7b..6a5c4e8 100644
--- a/test/libcxx/assertions/debug_mode_compatibility.pass.cpp
+++ b/test/libcxx/assertions/debug_mode_compatibility.pass.cpp
@@ -16,7 +16,6 @@
// failures when back-deploying.
// UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11|12}}
-#include <__assert>
#include <cassert>
bool handler_called = false;
diff --git a/test/libcxx/assertions/default_handler.abort.pass.cpp b/test/libcxx/assertions/default_handler.abort.pass.cpp
index 5be0997..4e1cb9e 100644
--- a/test/libcxx/assertions/default_handler.abort.pass.cpp
+++ b/test/libcxx/assertions/default_handler.abort.pass.cpp
@@ -14,7 +14,6 @@
// failures when back-deploying.
// UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11|12}}
-#include <__assert>
#include <csignal>
#include <cstdlib>
diff --git a/test/libcxx/assertions/default_handler.availability.verify.cpp b/test/libcxx/assertions/default_handler.availability.verify.cpp
index 93d6d02..6fc8d16 100644
--- a/test/libcxx/assertions/default_handler.availability.verify.cpp
+++ b/test/libcxx/assertions/default_handler.availability.verify.cpp
@@ -13,7 +13,7 @@
// REQUIRES: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11|12}}
-#include <__assert>
+#include <version> // any header would work
void f() {
_LIBCPP_ASSERT(true, "message"); // expected-error {{'__libcpp_assertion_handler' is unavailable}}
diff --git a/test/libcxx/assertions/headers_declare_assertion_handler.sh.cpp b/test/libcxx/assertions/headers_declare_assertion_handler.sh.cpp
new file mode 100644
index 0000000..0bdc308
--- /dev/null
+++ b/test/libcxx/assertions/headers_declare_assertion_handler.sh.cpp
@@ -0,0 +1,769 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Test that all public C++ headers define the assertion handler.
+
+// We flag uses of the assertion handler in older dylibs at compile-time to avoid runtime
+// failures when back-deploying.
+// UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11|12}}
+
+// The system-provided <uchar.h> seems to be broken on AIX, which trips up this test.
+// XFAIL: LIBCXX-AIX-FIXME
+
+/*
+BEGIN-SCRIPT
+
+for i, header in enumerate(public_headers):
+ # Skip C compatibility headers.
+ if header.endswith('.h'):
+ continue
+
+ vars = {
+ 'run': 'RUN',
+ 'i': i,
+ 'restrictions': ' && ' + header_restrictions[header] if header in header_restrictions else '',
+ 'header': header
+ }
+
+ print("""\
+// {run}: %{{build}} -DTEST_{i}
+#if defined(TEST_{i}){restrictions}
+# include <{header}>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+""".format(**vars))
+
+END-SCRIPT
+*/
+
+#include <__config>
+
+// Prevent <ext/hash_map> from generating deprecated warnings for this test.
+#if defined(__DEPRECATED)
+# undef __DEPRECATED
+#endif
+
+int main(int, char**) { return 0; }
+
+// DO NOT MANUALLY EDIT ANYTHING BETWEEN THE MARKERS BELOW
+// GENERATED-MARKER
+// RUN: %{build} -DTEST_0
+#if defined(TEST_0)
+# include <algorithm>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_1
+#if defined(TEST_1)
+# include <any>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_2
+#if defined(TEST_2)
+# include <array>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_3
+#if defined(TEST_3)
+# include <atomic>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_4
+#if defined(TEST_4) && !defined(_LIBCPP_HAS_NO_THREADS)
+# include <barrier>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_5
+#if defined(TEST_5)
+# include <bit>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_6
+#if defined(TEST_6)
+# include <bitset>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_7
+#if defined(TEST_7)
+# include <cassert>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_8
+#if defined(TEST_8)
+# include <ccomplex>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_9
+#if defined(TEST_9)
+# include <cctype>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_10
+#if defined(TEST_10)
+# include <cerrno>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_11
+#if defined(TEST_11)
+# include <cfenv>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_12
+#if defined(TEST_12)
+# include <cfloat>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_13
+#if defined(TEST_13)
+# include <charconv>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_14
+#if defined(TEST_14)
+# include <chrono>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_15
+#if defined(TEST_15)
+# include <cinttypes>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_16
+#if defined(TEST_16)
+# include <ciso646>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_17
+#if defined(TEST_17)
+# include <climits>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_18
+#if defined(TEST_18) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <clocale>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_19
+#if defined(TEST_19)
+# include <cmath>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_20
+#if defined(TEST_20) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <codecvt>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_21
+#if defined(TEST_21)
+# include <compare>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_22
+#if defined(TEST_22)
+# include <complex>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_24
+#if defined(TEST_24)
+# include <concepts>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_25
+#if defined(TEST_25)
+# include <condition_variable>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_26
+#if defined(TEST_26)
+# include <coroutine>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_27
+#if defined(TEST_27)
+# include <csetjmp>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_28
+#if defined(TEST_28)
+# include <csignal>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_29
+#if defined(TEST_29)
+# include <cstdarg>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_30
+#if defined(TEST_30)
+# include <cstdbool>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_31
+#if defined(TEST_31)
+# include <cstddef>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_32
+#if defined(TEST_32)
+# include <cstdint>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_33
+#if defined(TEST_33)
+# include <cstdio>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_34
+#if defined(TEST_34)
+# include <cstdlib>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_35
+#if defined(TEST_35)
+# include <cstring>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_36
+#if defined(TEST_36)
+# include <ctgmath>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_37
+#if defined(TEST_37)
+# include <ctime>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_39
+#if defined(TEST_39)
+# include <cuchar>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_40
+#if defined(TEST_40) && !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
+# include <cwchar>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_41
+#if defined(TEST_41) && !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
+# include <cwctype>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_42
+#if defined(TEST_42)
+# include <deque>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_44
+#if defined(TEST_44)
+# include <exception>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_45
+#if defined(TEST_45)
+# include <execution>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_47
+#if defined(TEST_47) && !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
+# include <filesystem>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_49
+#if defined(TEST_49)
+# include <format>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_50
+#if defined(TEST_50)
+# include <forward_list>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_51
+#if defined(TEST_51) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <fstream>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_52
+#if defined(TEST_52)
+# include <functional>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_53
+#if defined(TEST_53) && !defined(_LIBCPP_HAS_NO_THREADS)
+# include <future>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_54
+#if defined(TEST_54)
+# include <initializer_list>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_56
+#if defined(TEST_56) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <iomanip>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_57
+#if defined(TEST_57) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <ios>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_58
+#if defined(TEST_58)
+# include <iosfwd>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_59
+#if defined(TEST_59) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <iostream>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_60
+#if defined(TEST_60) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <istream>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_61
+#if defined(TEST_61)
+# include <iterator>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_62
+#if defined(TEST_62) && !defined(_LIBCPP_HAS_NO_THREADS)
+# include <latch>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_63
+#if defined(TEST_63)
+# include <limits>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_65
+#if defined(TEST_65)
+# include <list>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_66
+#if defined(TEST_66) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <locale>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_68
+#if defined(TEST_68)
+# include <map>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_70
+#if defined(TEST_70)
+# include <memory>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_71
+#if defined(TEST_71) && !defined(_LIBCPP_HAS_NO_THREADS)
+# include <mutex>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_72
+#if defined(TEST_72)
+# include <new>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_73
+#if defined(TEST_73)
+# include <numbers>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_74
+#if defined(TEST_74)
+# include <numeric>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_75
+#if defined(TEST_75)
+# include <optional>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_76
+#if defined(TEST_76) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <ostream>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_77
+#if defined(TEST_77)
+# include <queue>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_78
+#if defined(TEST_78)
+# include <random>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_79
+#if defined(TEST_79)
+# include <ranges>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_80
+#if defined(TEST_80)
+# include <ratio>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_81
+#if defined(TEST_81) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <regex>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_82
+#if defined(TEST_82)
+# include <scoped_allocator>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_83
+#if defined(TEST_83) && !defined(_LIBCPP_HAS_NO_THREADS)
+# include <semaphore>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_84
+#if defined(TEST_84)
+# include <set>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_86
+#if defined(TEST_86) && !defined(_LIBCPP_HAS_NO_THREADS)
+# include <shared_mutex>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_87
+#if defined(TEST_87)
+# include <span>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_88
+#if defined(TEST_88) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <sstream>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_89
+#if defined(TEST_89)
+# include <stack>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_92
+#if defined(TEST_92)
+# include <stdexcept>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_96
+#if defined(TEST_96) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <streambuf>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_97
+#if defined(TEST_97)
+# include <string>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_99
+#if defined(TEST_99)
+# include <string_view>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_100
+#if defined(TEST_100) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+# include <strstream>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_101
+#if defined(TEST_101)
+# include <system_error>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_103
+#if defined(TEST_103) && !defined(_LIBCPP_HAS_NO_THREADS)
+# include <thread>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_104
+#if defined(TEST_104)
+# include <tuple>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_105
+#if defined(TEST_105)
+# include <type_traits>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_106
+#if defined(TEST_106)
+# include <typeindex>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_107
+#if defined(TEST_107)
+# include <typeinfo>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_109
+#if defined(TEST_109)
+# include <unordered_map>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_110
+#if defined(TEST_110)
+# include <unordered_set>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_111
+#if defined(TEST_111)
+# include <utility>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_112
+#if defined(TEST_112)
+# include <valarray>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_113
+#if defined(TEST_113)
+# include <variant>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_114
+#if defined(TEST_114)
+# include <vector>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_115
+#if defined(TEST_115)
+# include <version>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_118
+#if defined(TEST_118)
+# include <experimental/algorithm>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_119
+#if defined(TEST_119) && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES)
+# include <experimental/coroutine>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_120
+#if defined(TEST_120) && __cplusplus >= 201103L
+# include <experimental/deque>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_121
+#if defined(TEST_121) && __cplusplus >= 201103L
+# include <experimental/forward_list>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_122
+#if defined(TEST_122)
+# include <experimental/functional>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_123
+#if defined(TEST_123)
+# include <experimental/iterator>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_124
+#if defined(TEST_124) && __cplusplus >= 201103L
+# include <experimental/list>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_125
+#if defined(TEST_125) && __cplusplus >= 201103L
+# include <experimental/map>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_126
+#if defined(TEST_126) && __cplusplus >= 201103L
+# include <experimental/memory_resource>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_127
+#if defined(TEST_127)
+# include <experimental/propagate_const>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_128
+#if defined(TEST_128) && !defined(_LIBCPP_HAS_NO_LOCALIZATION) && __cplusplus >= 201103L
+# include <experimental/regex>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_129
+#if defined(TEST_129) && __cplusplus >= 201103L
+# include <experimental/set>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_130
+#if defined(TEST_130)
+# include <experimental/simd>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_131
+#if defined(TEST_131) && __cplusplus >= 201103L
+# include <experimental/string>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_132
+#if defined(TEST_132)
+# include <experimental/type_traits>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_133
+#if defined(TEST_133) && __cplusplus >= 201103L
+# include <experimental/unordered_map>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_134
+#if defined(TEST_134) && __cplusplus >= 201103L
+# include <experimental/unordered_set>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_135
+#if defined(TEST_135)
+# include <experimental/utility>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_136
+#if defined(TEST_136) && __cplusplus >= 201103L
+# include <experimental/vector>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_137
+#if defined(TEST_137)
+# include <ext/hash_map>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// RUN: %{build} -DTEST_138
+#if defined(TEST_138)
+# include <ext/hash_set>
+ using HandlerType = decltype(std::__libcpp_assertion_handler);
+#endif
+
+// GENERATED-MARKER
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index 4aefa89..d337935 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -15,9 +15,14 @@
COMMAND "${Python3_EXECUTABLE}" "${LIBCXX_SOURCE_DIR}/utils/generate_private_header_tests.py"
COMMENT "Generate tests for ensuring that detail headers are private.")
+add_custom_target(libcxx-generate-assertion-tests
+ COMMAND "${Python3_EXECUTABLE}" "${LIBCXX_SOURCE_DIR}/utils/generate_assertion_tests.py"
+ COMMENT "Generate tests for inclusion of <__assert>.")
+
add_custom_target(libcxx-generate-files
DEPENDS libcxx-generate-public-header-transitive-inclusion-tests
libcxx-generate-public-header-tests
libcxx-generate-feature-test-macros
libcxx-generate-private-header-tests
+ libcxx-generate-assertion-tests
COMMENT "Create all the auto-generated files in libc++ and its tests.")
diff --git a/utils/generate_assertion_tests.py b/utils/generate_assertion_tests.py
new file mode 100755
index 0000000..7ef30bc
--- /dev/null
+++ b/utils/generate_assertion_tests.py
@@ -0,0 +1,135 @@
+#!/usr/bin/env python
+
+import contextlib
+import glob
+import io
+import os
+import pathlib
+import re
+
+header_restrictions = {
+ "barrier": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "future": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "latch": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "mutex": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "semaphore": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "shared_mutex": "!defined(_LIBCPP_HAS_NO_THREADS)",
+ "thread": "!defined(_LIBCPP_HAS_NO_THREADS)",
+
+ "filesystem": "!defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)",
+
+ "clocale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "codecvt": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "fstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "iomanip": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "ios": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "iostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "istream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "locale.h": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "locale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "ostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "sstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "streambuf": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+ "strstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+
+ "wctype.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
+ "cwctype": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
+ "cwchar": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
+ "wchar.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)",
+
+ "experimental/coroutine": "!defined(_LIBCPP_HAS_NO_EXPERIMENTAL_COROUTINES)",
+
+ "experimental/regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION) && __cplusplus >= 201103L",
+ "experimental/deque": "__cplusplus >= 201103L",
+ "experimental/map": "__cplusplus >= 201103L",
+ "experimental/memory_resource": "__cplusplus >= 201103L",
+ "experimental/forward_list": "__cplusplus >= 201103L",
+ "experimental/list": "__cplusplus >= 201103L",
+ "experimental/set": "__cplusplus >= 201103L",
+ "experimental/string": "__cplusplus >= 201103L",
+ "experimental/unordered_map": "__cplusplus >= 201103L",
+ "experimental/unordered_set": "__cplusplus >= 201103L",
+ "experimental/vector": "__cplusplus >= 201103L",
+}
+
+private_headers_still_public_in_modules = [
+ '__assert', '__bsd_locale_defaults.h', '__bsd_locale_fallbacks.h', '__config',
+ '__config_site.in', '__debug', '__hash_table',
+ '__libcpp_version', '__threading_support', '__tree', '__undef_macros'
+]
+
+def find_script(file):
+ """Finds the script used to generate a file inside the file itself. The script is delimited by
+ BEGIN-SCRIPT and END-SCRIPT markers.
+ """
+ with open(file, 'r') as f:
+ content = f.read()
+
+ match = re.search(r'^BEGIN-SCRIPT$(.+)^END-SCRIPT$', content, flags=re.MULTILINE | re.DOTALL)
+ if not match:
+ raise RuntimeError("Was unable to find a script delimited with BEGIN-SCRIPT/END-SCRIPT markers in {}".format(test_file))
+ return match.group(1)
+
+def execute_script(script, variables):
+ """Executes the provided Mako template with the given variables available during the
+ evaluation of the script, and returns the result.
+ """
+ code = compile(script, 'fake-filename', 'exec')
+ output = io.StringIO()
+ with contextlib.redirect_stdout(output):
+ exec(code, variables)
+ output = output.getvalue()
+ return output
+
+def generate_new_file(file, new_content):
+ """Generates the new content of the file by inserting the new content in-between
+ two '// GENERATED-MARKER' markers located in the file.
+ """
+ with open(file, 'r') as f:
+ old_content = f.read()
+
+ try:
+ before, begin_marker, _, end_marker, after = re.split(r'(// GENERATED-MARKER\n)', old_content, flags=re.MULTILINE | re.DOTALL)
+ except ValueError:
+ raise RuntimeError("Failed to split {} based on markers, please make sure the file has exactly two '// GENERATED-MARKER' occurrences".format(file))
+
+ return before + begin_marker + new_content + end_marker + after
+
+def produce(test_file, variables):
+ script = find_script(test_file)
+ result = execute_script(script, variables)
+ new_content = generate_new_file(test_file, result)
+ with open(test_file, 'w', newline='\n') as f:
+ f.write(new_content)
+
+def is_header(file):
+ """Returns whether the given file is a header (i.e. not a directory or the modulemap file)."""
+ return not file.is_dir() and not file.name == 'module.modulemap'
+
+def main():
+ monorepo_root = pathlib.Path(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+ include = pathlib.Path(os.path.join(monorepo_root, 'libcxx', 'include'))
+ test = pathlib.Path(os.path.join(monorepo_root, 'libcxx', 'test'))
+ assert(monorepo_root.exists())
+
+ toplevel_headers = sorted(str(p.relative_to(include)) for p in include.glob('[a-z]*') if is_header(p))
+ experimental_headers = sorted(str(p.relative_to(include)) for p in include.glob('experimental/[a-z]*') if is_header(p))
+ extended_headers = sorted(str(p.relative_to(include)) for p in include.glob('ext/[a-z]*') if is_header(p))
+ public_headers = toplevel_headers + experimental_headers + extended_headers
+ private_headers = sorted(str(p.relative_to(include)) for p in include.rglob('*') if is_header(p) and str(p.relative_to(include)).startswith('__'))
+ variables = {
+ 'toplevel_headers': toplevel_headers,
+ 'experimental_headers': experimental_headers,
+ 'extended_headers': extended_headers,
+ 'public_headers': public_headers,
+ 'private_headers': private_headers,
+ 'header_restrictions': header_restrictions,
+ 'private_headers_still_public_in_modules': private_headers_still_public_in_modules
+ }
+
+ produce(test.joinpath('libcxx/assertions/headers_declare_assertion_handler.sh.cpp'), variables)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/utils/generate_feature_test_macro_components.py b/utils/generate_feature_test_macro_components.py
index 14e5b4e..191d0ee 100755
--- a/utils/generate_feature_test_macro_components.py
+++ b/utils/generate_feature_test_macro_components.py
@@ -937,6 +937,7 @@
*/
+#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)