Fix Clang deprecation warning for json_pointer operator== with ordered_json#5289
Open
nlohmann wants to merge 1 commit into
Open
Fix Clang deprecation warning for json_pointer operator== with ordered_json#5289nlohmann wants to merge 1 commit into
nlohmann wants to merge 1 commit into
Conversation
nlohmann
force-pushed
the
claude/issue-5288-25rr9a
branch
from
July 22, 2026 11:14
00bf293 to
302a1f5
Compare
…d_json is_comparable used a flat && chain to both exclude json_pointer/string comparisons (added for #4621) and check whether Compare(A, B) is well-formed. Naming std::is_constructible<decltype(...)> as a later operand of that chain still causes the decltype to be substituted regardless of the first operand's value, since the operands aren't lazily deferred like std::conjunction would defer them. That instantiates the transparent std::equal_to<>::operator() used by ordered_json, whose noexcept-specifier evaluates the deprecated json_pointer/string operator==, which Clang (unlike GCC in this case) warns about even though the result is discarded. Split is_comparable so the Compare(A, B) checks live in a separate helper that is only referenced from the specialization selected when is_json_pointer_of is false, so the decltype is never written when A/B are a json_pointer/string pair, regardless of compiler. Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com>
nlohmann
force-pushed
the
claude/issue-5288-25rr9a
branch
from
July 22, 2026 13:53
302a1f5 to
c16615e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your pull request here. Please read the text below the line and make sure you follow the checklist.
Fixes #5288.
ordered_jsonuses a transparent comparator (std::equal_to<>).is_comparable(detail/meta/type_traits.hpp) previously guarded theCompare(A, B)well-formedness checks with a flat&&chain, with!is_json_pointer_of<A, B>::valueas the first operand (added for #4621). That guard doesn't stop the compiler from forming the later operands:std::is_constructible<decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>()))>is a separately-named class template, so itsdecltypeis substituted regardless of whether the first operand is false — plain&&chains of independently-named templates aren't a true lazy short-circuit (unlikestd::conjunction).That instantiates
std::equal_to<>::operator()(string, json_pointer), whosenoexcept(noexcept(t == u))clause (in libstdc++'sstl_function.h) resolvest == uto the deprecatedjson_pointer/stringoperator==(there's no non-deprecated overload for that pair). Clang warns on that unevaluated-context use with-Wdeprecated-declarations; GCC does not warn in this particular case, which is why the issue only reproduces on Clang.The fix splits
is_comparableso theCompare(A, B)checks live in a separate helper (is_comparable_no_json_pointer) that is only ever referenced from the specialization selected whenis_json_pointer_of<A, B>isfalse(dispatched via a plainbooltemplate parameter). This means the problematicdecltypeis only ever written — and thus only ever instantiated — whenA/Bare not ajson_pointer/string pair, regardless of compiler.make amalgamate.Testing
developbefore the fix (Clang warns, GCC doesn't).-Wdeprecated-declarations) across-std=c++11/14/17/20, for bothjsonandordered_json, using.at()/.contains()with bothjson_pointerandstd::stringkeys.unit-json_pointer,unit-comparison,unit-ordered_json, andunit-ordered_mapunit test suites (4478 assertions) against the patched header — all pass.Read the Contribution Guidelines for detailed information.
Generated by Claude Code