Harden JSON_HAS_RANGES detection for incomplete C++20 ranges implementations (#5161)

*  add regression test for #4440

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🐛 exclude breaking libraries

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🐛 exclude breaking libraries

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-06-30 13:33:01 +02:00
committed by GitHub
parent c5b2b26fdc
commit b7566c6293
3 changed files with 37 additions and 0 deletions
+9
View File
@@ -137,6 +137,15 @@
// ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error
#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
#define JSON_HAS_RANGES 0
// libstdc++ < 11 has incomplete C++20 ranges (issue #4440)
#elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
#define JSON_HAS_RANGES 0
// libc++ < 16 has incomplete C++20 ranges (issue #4440)
#elif defined(__clang__) && !defined(__apple_build_version__) \
&& __clang_major__ < 16 && defined(__GLIBCXX__)
#define JSON_HAS_RANGES 0
#elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000
#define JSON_HAS_RANGES 0
#elif defined(__cpp_lib_ranges)
#define JSON_HAS_RANGES 1
#else