Skip to content

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

Merged
nlohmann merged 3 commits into
developfrom
issue4440
Jun 30, 2026
Merged

Harden JSON_HAS_RANGES detection for incomplete C++20 ranges implementations#5161
nlohmann merged 3 commits into
developfrom
issue4440

Conversation

@nlohmann

@nlohmann nlohmann commented May 9, 2026

Copy link
Copy Markdown
Owner

Some standard libraries advertise __cpp_lib_ranges but ship an incomplete
C++20 ranges implementation. Constructing a basic_json from a view (e.g.
j | std::views::filter(...)) then asserts or fails to compile on those
toolchains.

This PR refines the JSON_HAS_RANGES feature detection to disable ranges
support on the affected standard libraries:

On these toolchains the library now falls back to JSON_HAS_RANGES 0
instead of enabling a broken code path. Toolchains with complete ranges
support are unaffected.

It also adds a regression test (unit-regression2.cpp) reproducing #4440
with std::views::filter, guarded by JSON_HAS_RANGES == 1 so it only runs
where ranges are actually available.

Closes #4440.
Closes #4051.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
nlohmann added 2 commits May 18, 2026 15:54
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

@github-actions github-actions Bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jun 18, 2026
@nlohmann nlohmann changed the title Add regression test for views Harden JSON_HAS_RANGES detection for incomplete C++20 ranges implementations Jun 30, 2026
@nlohmann nlohmann removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jun 30, 2026
@nlohmann nlohmann added this to the Release 3.12.1 milestone Jun 30, 2026
@nlohmann nlohmann merged commit b7566c6 into develop Jun 30, 2026
143 checks passed
@nlohmann nlohmann deleted the issue4440 branch June 30, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assert when using std::views::filter and GCC 10 compiler error using clang-16.0.5 when using gcc-13.1 standard library

1 participant