diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp index 539e234750e008..d59864eb87023d 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp @@ -108,7 +108,9 @@ constexpr bool test() { return value; }; assert(std::ranges::clamp(3, 2, 4, std::ranges::less{}, projection_function) == 3); -#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG +#if defined(_LIBCPP_HARDENING_MODE) && \ + _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ + _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG assert(counter <= 3); #endif } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp index 3b7c0ae0b80f08..c7ab3626044748 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp @@ -69,7 +69,7 @@ int main(int, char**) { std::sort_heap(first, last); LIBCPP_ASSERT(stats.copied == 0); LIBCPP_ASSERT(stats.moved <= 2 * n + n * logn); -#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG +#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG LIBCPP_ASSERT(stats.compared <= n * logn); #else LIBCPP_ASSERT(stats.compared <= 2 * n * logn + debug_comparisons); diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp index 1e636ea9afac47..ff69f39f6c06dc 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp @@ -246,7 +246,7 @@ void test_complexity() { std::ranges::sort_heap(first, last, &MyInt::Comp); LIBCPP_ASSERT(stats.copied == 0); LIBCPP_ASSERT(stats.moved <= 2 * n + n * logn); -#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG +#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG LIBCPP_ASSERT(stats.compared <= n * logn); #else LIBCPP_ASSERT(stats.compared <= 2 * n * logn + debug_comparisons); diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp index 0a35fad40e89a5..d103e8c2ddb33b 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp @@ -79,7 +79,7 @@ test_one(unsigned N, unsigned M) assert(ia[0] == static_cast(N)-1); assert(ia[N-1] == 0); assert(std::is_sorted(ia, ia+N, std::greater())); -#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG +#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG assert(pred.count() <= (N-1)); #endif } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp index f2f7d538d773f7..edacf3ce5d87ff 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp @@ -156,7 +156,7 @@ constexpr void test_comparator_invocation_count() { // The comparator is invoked only `min(left.size(), right.size())` times test_lexicographical_compare( std::array{0, 1, 2}, std::array{0, 1, 2, 3}, compare_last_digit_counting, std::strong_ordering::less); -#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG +#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG assert(compare_invocation_count <= 3); #else assert(compare_invocation_count <= 6); diff --git a/libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp b/libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp index 92bb7c9caea836..064d5c3a3fac4b 100644 --- a/libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp +++ b/libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp @@ -50,7 +50,7 @@ void test_iterator_sentinel() { assert(s.data() == std::data(arr)); } -#if _LIBCPP_STD_VER >= 26 +#if TEST_STD_VER >= 26 // P3029R1: deduction from `integral_constant` { std::span s{std::begin(arr), std::integral_constant{}}; diff --git a/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp b/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp index acb1e1f7d40755..0749617d056abf 100644 --- a/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp +++ b/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp @@ -110,7 +110,7 @@ int main(int, char**) err = std::ios_base::goodbit; t = std::tm(); I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); -#if _LIBCPP_VERSION +#if defined(_LIBCPP_VERSION) // libc++ points to the '/' after the month. assert(base(i) == in+2); #else @@ -129,7 +129,7 @@ int main(int, char**) err = std::ios_base::goodbit; t = std::tm(); I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t); -#if _LIBCPP_VERSION +#if defined(_LIBCPP_VERSION) // libc++ points to the '/' after the month. assert(base(i) == in+2); #else diff --git a/libcxx/test/support/check_assertion.h b/libcxx/test/support/check_assertion.h index cc841ceb237d8d..329ce819a6c8d0 100644 --- a/libcxx/test/support/check_assertion.h +++ b/libcxx/test/support/check_assertion.h @@ -392,7 +392,7 @@ bool ExpectDeath(DeathCause expected_cause, const char* stmt, Func&& func) { #define EXPECT_STD_TERMINATE(...) \ assert( ExpectDeath(DeathCause::StdTerminate, #__VA_ARGS__, __VA_ARGS__) ) -#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG +#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG #define TEST_LIBCPP_ASSERT_FAILURE(expr, message) \ assert(( ExpectDeath(DeathCause::VerboseAbort, #expr, [&]() { (void)(expr); }, MakeAssertionMessageMatcher(message)) )) #else diff --git a/libcxx/test/support/container_test_types.h b/libcxx/test/support/container_test_types.h index ed26ba5d40af51..b72bbbeaccf770 100644 --- a/libcxx/test/support/container_test_types.h +++ b/libcxx/test/support/container_test_types.h @@ -87,9 +87,16 @@ #include #include +#include #include +#include +#include #include +#include +#include +#include #include +#include #include "test_macros.h" @@ -420,12 +427,7 @@ bool operator <(CopyInsertable const& L, CopyInsertable const& R) { return L.data < R.data; } - -#ifdef _LIBCPP_BEGIN_NAMESPACE_STD -_LIBCPP_BEGIN_NAMESPACE_STD -#else namespace std { -#endif template struct hash< ::CopyInsertable > { typedef ::CopyInsertable argument_type; @@ -435,34 +437,7 @@ namespace std { return arg.data; } }; - template - class vector; - template - class deque; - template - class list; - template - class map; - template - class multimap; - template - class set; - template - class multiset; - template - class unordered_map; - template - class unordered_multimap; - template - class unordered_set; - template - class unordered_multiset; - -#ifdef _LIBCPP_END_NAMESPACE_STD -_LIBCPP_END_NAMESPACE_STD -#else -} // end namespace std -#endif +} // TCT - Test container type namespace TCT { diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h index 1b3313d0c1cfb0..29bc846fbbc832 100644 --- a/libcxx/test/support/filesystem_test_helper.h +++ b/libcxx/test/support/filesystem_test_helper.h @@ -18,6 +18,7 @@ #include #include #include // for printf +#include #include #include #include @@ -232,9 +233,9 @@ struct scoped_test_env if (size > static_cast::type>( std::numeric_limits::max())) { - fprintf(stderr, "create_file(%s, %ju) too large\n", - filename.c_str(), size); - abort(); + std::fprintf(stderr, "create_file(%s, %ju) too large\n", + filename.c_str(), size); + std::abort(); } #if defined(_WIN32) || defined(__MVS__) @@ -244,20 +245,20 @@ struct scoped_test_env #endif FILE* file = utils::fopen64(filename.c_str(), "w" FOPEN_CLOEXEC_FLAG); if (file == nullptr) { - fprintf(stderr, "fopen %s failed: %s\n", filename.c_str(), - strerror(errno)); - abort(); + std::fprintf(stderr, "fopen %s failed: %s\n", filename.c_str(), + std::strerror(errno)); + std::abort(); } if (utils::ftruncate64( fileno(file), static_cast(size)) == -1) { - fprintf(stderr, "ftruncate %s %ju failed: %s\n", filename.c_str(), - size, strerror(errno)); - fclose(file); - abort(); + std::fprintf(stderr, "ftruncate %s %ju failed: %s\n", filename.c_str(), + size, std::strerror(errno)); + std::fclose(file); + std::abort(); } - fclose(file); + std::fclose(file); return filename; } @@ -616,10 +617,9 @@ struct ExceptionChecker { }(); assert(format == Err.what()); if (format != Err.what()) { - fprintf(stderr, - "filesystem_error::what() does not match expected output:\n"); - fprintf(stderr, " expected: \"%s\"\n", format.c_str()); - fprintf(stderr, " actual: \"%s\"\n\n", Err.what()); + std::fprintf(stderr, "filesystem_error::what() does not match expected output:\n"); + std::fprintf(stderr, " expected: \"%s\"\n", format.c_str()); + std::fprintf(stderr, " actual: \"%s\"\n\n", Err.what()); } } @@ -639,23 +639,23 @@ inline fs::path GetWindowsInaccessibleDir() { continue; // Basic sanity checks on the directory_entry if (!ent.exists() || !ent.is_directory()) { - fprintf(stderr, "The expected inaccessible directory \"%s\" was found " - "but doesn't behave as expected, skipping tests " - "regarding it\n", dir.string().c_str()); + std::fprintf(stderr, "The expected inaccessible directory \"%s\" was found " + "but doesn't behave as expected, skipping tests " + "regarding it\n", dir.string().c_str()); return fs::path(); } // Check that it indeed is inaccessible as expected (void)fs::exists(ent, ec); if (!ec) { - fprintf(stderr, "The expected inaccessible directory \"%s\" was found " - "but seems to be accessible, skipping tests " - "regarding it\n", dir.string().c_str()); + std::fprintf(stderr, "The expected inaccessible directory \"%s\" was found " + "but seems to be accessible, skipping tests " + "regarding it\n", dir.string().c_str()); return fs::path(); } return ent; } - fprintf(stderr, "No inaccessible directory \"%s\" found, skipping tests " - "regarding it\n", dir.string().c_str()); + std::fprintf(stderr, "No inaccessible directory \"%s\" found, skipping tests " + "regarding it\n", dir.string().c_str()); return fs::path(); } diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py index ea841acf3a3d41..3aadc54cf92dc5 100644 --- a/libcxx/utils/libcxx/test/params.py +++ b/libcxx/utils/libcxx/test/params.py @@ -374,11 +374,12 @@ def getSuitableClangTidy(cfg): ), Parameter( name="hardening_mode", - choices=["none", "fast", "extensive", "debug"], + choices=["none", "fast", "extensive", "debug", "undefined"], type=str, - default="none", + default="undefined", help="Whether to enable one of the hardening modes when compiling the test suite. This is only " - "meaningful when running the tests against libc++.", + "meaningful when running the tests against libc++. By default, no hardening mode is specified " + "so the default hardening mode of the standard library will be used (if any).", actions=lambda hardening_mode: filter( None, [ @@ -386,7 +387,7 @@ def getSuitableClangTidy(cfg): AddCompileFlag("-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST") if hardening_mode == "fast" else None, AddCompileFlag("-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE") if hardening_mode == "extensive" else None, AddCompileFlag("-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG") if hardening_mode == "debug" else None, - AddFeature("libcpp-hardening-mode={}".format(hardening_mode)), + AddFeature("libcpp-hardening-mode={}".format(hardening_mode)) if hardening_mode != "undefined" else None, ], ), ),