Build the tests with C++17/C++20-only sections in those standards

cmake/test.cmake only adds the _cpp17/_cpp20 variants of a unit test if the
file mentions JSON_HAS_CPP_17/JSON_HAS_CPP_20. Several files have sections
that need C++17 or C++20 (std::filesystem::path, std::string_view, char8_t,
std::u8string, operator<=>, ranges) but never mention the macros, so by
default these sections were only compiled away in the C++11 build and only
ran in the CI jobs that force a standard.

Mention the macros next to the guarded sections, as the other tests do:
unit-to_json-rvalue.cpp (C++17 and C++20), unit-json_view_builder.cpp
(C++17), unit-class_parser.cpp, unit-recursion_depth_limit.cpp,
unit-ubjson_valueless.cpp, unit-custom-number-types.cpp and
unit-allocator.cpp (C++20).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-11-16 12:40:54 +01:00
1 parent abbc29963a
commit 934b12a9e1
8 files changed
+61 -5

No files matched your search

+1 -2
View File
@@ -445,8 +445,7 @@ json_test_add_test_for(src/unit-stream-bulk-scan.cpp
# with other values of JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE: 1 (the smallest),
# 1000000 (so large that the budget cannot be reached), and the largest value of
# a 64-bit integer (which saturates the limit already at the first byte, and is
# clamped to the largest std::size_t where that has 32 bits). The file does not
# mention JSON_HAS_CPP_<n>, so only C++11 is built unless the standards are forced
# clamped to the largest std::size_t where that has 32 bits)
json_test_set_test_options(test-ubjson_valueless_rate_1
COMPILE_DEFINITIONS JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE=1
)