Skip to content

Fix Clang deprecation warning for json_pointer operator== with ordered_json#5289

Open
nlohmann wants to merge 1 commit into
developfrom
claude/issue-5288-25rr9a
Open

Fix Clang deprecation warning for json_pointer operator== with ordered_json#5289
nlohmann wants to merge 1 commit into
developfrom
claude/issue-5288-25rr9a

Conversation

@nlohmann

Copy link
Copy Markdown
Owner

Describe your pull request here. Please read the text below the line and make sure you follow the checklist.

Fixes #5288.

ordered_json uses a transparent comparator (std::equal_to<>). is_comparable (detail/meta/type_traits.hpp) previously guarded the Compare(A, B) well-formedness checks with a flat && chain, with !is_json_pointer_of<A, B>::value as 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 its decltype is substituted regardless of whether the first operand is false — plain && chains of independently-named templates aren't a true lazy short-circuit (unlike std::conjunction).

That instantiates std::equal_to<>::operator()(string, json_pointer), whose noexcept(noexcept(t == u)) clause (in libstdc++'s stl_function.h) resolves t == u to the deprecated json_pointer/string operator== (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_comparable so the Compare(A, B) checks live in a separate helper (is_comparable_no_json_pointer) that is only ever referenced from the specialization selected when is_json_pointer_of<A, B> is false (dispatched via a plain bool template parameter). This means the problematic decltype is only ever written — and thus only ever instantiated — when A/B are not a json_pointer/string pair, regardless of compiler.

  • The changes are described in detail, both the what and why.
  • If applicable, an existing issue is referenced.
  • The Code coverage remained at 100%. A test case for every new line of code.
  • If applicable, the documentation is updated.
  • The source code is amalgamated by running make amalgamate.

Testing

  • Reproduced the warning from Deprecation warning for operator== when using ordered_json when building with clang #5288 with both Clang 18 and GCC 13 on develop before the fix (Clang warns, GCC doesn't).
  • After the fix, both compilers are warning-free (-Wdeprecated-declarations) across -std=c++11/14/17/20, for both json and ordered_json, using .at()/.contains() with both json_pointer and std::string keys.
  • Ran the unit-json_pointer, unit-comparison, unit-ordered_json, and unit-ordered_map unit test suites (4478 assertions) against the patched header — all pass.
  • No new test case was added since this is a compiler-warning-only fix with no behavioral change; happy to add one if there's a preferred way to assert "no deprecation warning" in this test suite.

Read the Contribution Guidelines for detailed information.


Generated by Claude Code

@github-actions github-actions Bot added the M label Jul 22, 2026
@nlohmann
nlohmann force-pushed the claude/issue-5288-25rr9a branch from 00bf293 to 302a1f5 Compare July 22, 2026 11:14
…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
nlohmann force-pushed the claude/issue-5288-25rr9a branch from 302a1f5 to c16615e Compare July 22, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecation warning for operator== when using ordered_json when building with clang

1 participant