Skip to content

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

Description

@Jezza2

Description

When building with clangd and using ordered_json, calling .at(ordered_json::json_pointer{}) produces a deprecation warning for operator==(std::string, std::string). No warning is displayed with GCC.

Reproduction steps

Build the below code sample using clang.

Expected vs. actual results

Either the .at() overload for ordered_json::json_pointer should be marked deprecated, or there should be no deprecation warning shown. Behaviour should also be consistent across compilers.

Minimal code example

#include "json/json.hpp"

using json = nlohmann::ordered_json;

int main()
{
    const json j = R"({"hi":"nlohmann"})"_json;
    j.at(json::json_pointer{"/hi"});
}

Error messages

In file included from /workspaces/scmessage-refactor/test.cpp:1:
In file included from /workspaces/scmessage-refactor/thirdparty/json/json.hpp:23:
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/functional:49:
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_function.h:497:43: warning: 'operator==' is deprecated: Since 3.11.2; use operator==(json_pointer, json_pointer) [-Wdeprecated-declarations]
  497 |         noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))
      |                                                  ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:4108:10: note: in instantiation of exception specification for 'operator()<std::basic_string<char>, nlohmann::json_pointer<std::basic_string<char>>>' requested here
 4108 | decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
      |          ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:4120:31: note: during template argument deduction for class template partial specialization 'is_comparable<Compare, A, B, void_t<decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>>' [with Compare = std::equal_to<void>, A = std::basic_string<char>, B = nlohmann::json_pointer<std::basic_string<char>>]
 4120 |                               is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value
      |                               ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:4120:31: note: in instantiation of template class 'nlohmann::detail::is_comparable<std::equal_to<void>, std::basic_string<char>, nlohmann::json_pointer<std::basic_string<char>>>' requested here
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:4138:5: note: in instantiation of template type alias 'is_usable_as_key_type' requested here
 4138 |     is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
      |     ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:22044:26: note: in instantiation of template type alias 'is_usable_as_basic_json_key_type' requested here
 22044 |                  detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>
       |                          ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:22045:15: note: while substituting prior template arguments into non-type template parameter [with KeyType = json::json_pointer]
 22045 |     reference at(KeyType && key)
       |               ^~~~~~~~~~~~~~~~~~
 22046 |     {
       |     ~
 22047 |         // at only works for objects
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22048 |         if (JSON_HEDLEY_UNLIKELY(!is_object()))
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22049 |         {
       |         ~
 22050 |             JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this));
       |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22051 |         }
       |         ~
 22052 | 
 22053 |         auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22054 |         if (it == m_data.m_value.object->end())
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22055 |         {
       |         ~
 22056 |             JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward<KeyType>(key)), "' not found"), this));
       |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22057 |         }
       |         ~
 22058 |         return set_parent(it->second);
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22059 |     }
       |     ~
/workspaces/scmessage-refactor/test.cpp:8:7: note: while substituting deduced template arguments into function template 'at' [with KeyType = json::json_pointer, $1 = (no value)]
    8 |     j.at(json::json_pointer{"/hi"});
      |       ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:15453:13: note: 'operator==' has been explicitly marked deprecated here
 15453 | inline bool operator==(const StringType& lhs,
       |             ^
In file included from /workspaces/scmessage-refactor/test.cpp:1:
In file included from /workspaces/scmessage-refactor/thirdparty/json/json.hpp:23:
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/functional:49:
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_function.h:497:43: warning: 'operator==<std::basic_string<char>, std::basic_string<char>>' is deprecated: Since 3.11.2; use operator==(json_pointer, json_pointer) [-Wdeprecated-declarations]
  497 |         noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))
      |                                                  ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:15452:1: note: 'operator==<std::basic_string<char>, std::basic_string<char>>' has been explicitly marked deprecated here
 15452 | JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer))
       | ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:1376:75: note: expanded from macro 'JSON_HEDLEY_DEPRECATED_FOR'
 1376 |     #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
      |                                                                           ^
In file included from /workspaces/scmessage-refactor/test.cpp:1:
In file included from /workspaces/scmessage-refactor/thirdparty/json/json.hpp:23:
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/functional:49:
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_function.h:497:43: warning: 'operator==' is deprecated: Since 3.11.2; use operator==(json_pointer, json_pointer) [-Wdeprecated-declarations]
  497 |         noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))
      |                                                  ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:4109:10: note: in instantiation of exception specification for 'operator()<nlohmann::json_pointer<std::basic_string<char>>, std::basic_string<char>>' requested here
 4109 | decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
      |          ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:4120:31: note: during template argument deduction for class template partial specialization 'is_comparable<Compare, A, B, void_t<decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>>' [with Compare = std::equal_to<void>, A = std::basic_string<char>, B = nlohmann::json_pointer<std::basic_string<char>>]
 4120 |                               is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value
      |                               ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:4120:31: note: in instantiation of template class 'nlohmann::detail::is_comparable<std::equal_to<void>, std::basic_string<char>, nlohmann::json_pointer<std::basic_string<char>>>' requested here
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:4138:5: note: in instantiation of template type alias 'is_usable_as_key_type' requested here
 4138 |     is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
      |     ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:22044:26: note: in instantiation of template type alias 'is_usable_as_basic_json_key_type' requested here
 22044 |                  detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0>
       |                          ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:22045:15: note: while substituting prior template arguments into non-type template parameter [with KeyType = json::json_pointer]
 22045 |     reference at(KeyType && key)
       |               ^~~~~~~~~~~~~~~~~~
 22046 |     {
       |     ~
 22047 |         // at only works for objects
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22048 |         if (JSON_HEDLEY_UNLIKELY(!is_object()))
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22049 |         {
       |         ~
 22050 |             JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this));
       |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22051 |         }
       |         ~
 22052 | 
 22053 |         auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22054 |         if (it == m_data.m_value.object->end())
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22055 |         {
       |         ~
 22056 |             JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward<KeyType>(key)), "' not found"), this));
       |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22057 |         }
       |         ~
 22058 |         return set_parent(it->second);
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22059 |     }
       |     ~
/workspaces/scmessage-refactor/test.cpp:8:7: note: while substituting deduced template arguments into function template 'at' [with KeyType = json::json_pointer, $1 = (no value)]
    8 |     j.at(json::json_pointer{"/hi"});
      |       ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:15444:13: note: 'operator==' has been explicitly marked deprecated here
 15444 | inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
       |             ^
In file included from /workspaces/scmessage-refactor/test.cpp:1:
In file included from /workspaces/scmessage-refactor/thirdparty/json/json.hpp:23:
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/functional:49:
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_function.h:497:43: warning: 'operator==<std::basic_string<char>, std::basic_string<char>>' is deprecated: Since 3.11.2; use operator==(json_pointer, json_pointer) [-Wdeprecated-declarations]
  497 |         noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))
      |                                                  ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:15443:1: note: 'operator==<std::basic_string<char>, std::basic_string<char>>' has been explicitly marked deprecated here
 15443 | JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer))
       | ^
/workspaces/scmessage-refactor/thirdparty/json/json.hpp:1376:75: note: expanded from macro 'JSON_HEDLEY_DEPRECATED_FOR'
 1376 |     #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
      |                                                                           ^
4 warnings generated.

Compiler and operating system

Debian 13, Clang 19.1.7, GCC 14.2.0

Library version

3.12.0

Validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions