nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
42.97k stars 6.72k forks source link

Unexpected deprecation warning in 3.11.2 #3850

Open garethsb opened 1 year ago

garethsb commented 1 year ago

Description

Deprecation of mixed type comparison operators of json_pointer seems to have resulted in unexpected deprecation warning when using json::at with json_pointer, I think because is_comparable is evaluated while calculating the overload candidates...

Reproduction steps

Compile example with GCC against 3.11.2. Works OK with 3.11.1.

Expected vs. actual results

Expected:

No warnings.

Actual:

Several long-winded warnings.

Minimal code example

#include <nlohmann/json.hpp>

void meow()
{
    nlohmann::json j;
    nlohmann::json::json_pointer p;
    j.at(p);
}

Error messages

<source>: In instantiation of 'struct nlohmann::json_abi_v3_11_2::detail::is_comparable<std::less<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char>, nlohmann::json_abi_v3_11_2::json_pointer<std::__cxx11::basic_string<char> >&, void>':
<source>:3924:31:   required by substitution of 'template<class KeyType, typename std::enable_if<typename std::conditional<(typename std::conditional<(((nlohmann::json_abi_v3_11_2::detail::is_comparable<std::less<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char>, KeyType, void>::value && (!(true && std::is_same<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, std::__cxx11::basic_string<char> >::value))) && ((! true) || std::integral_constant<bool, false>::value)) && (! nlohmann::json_abi_v3_11_2::detail::is_specialization_of<nlohmann::json_abi_v3_11_2::json_pointer, typename std::remove_cv<typename std::remove_reference<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::type>::type>::value)), std::integral_constant<bool, true>, std::integral_constant<bool, false> >::type::value && (! nlohmann::json_abi_v3_11_2::detail::is_json_iterator_of<nlohmann::json_abi_v3_11_2::basic_json<>, typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value)), std::integral_constant<bool, true>, std::integral_constant<bool, false> >::type::value, int>::type <anonymous> > const nlohmann::json_abi_v3_11_2::basic_json<>::value_type& nlohmann::json_abi_v3_11_2::basic_json<>::at(KeyType&&) const [with KeyType = nlohmann::json_abi_v3_11_2::json_pointer<std::__cxx11::basic_string<char> >&; typename std::enable_if<typename std::conditional<(typename std::conditional<(((nlohmann::json_abi_v3_11_2::detail::is_comparable<std::less<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char>, KeyType, void>::value && (!(true && std::is_same<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, std::__cxx11::basic_string<char> >::value))) && ((! true) || std::integral_constant<bool, false>::value)) && (! nlohmann::json_abi_v3_11_2::detail::is_specialization_of<nlohmann::json_abi_v3_11_2::json_pointer, typename std::remove_cv<typename std::remove_reference<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::type>::type>::value)), std::integral_constant<bool, true>, std::integral_constant<bool, false> >::type::value && (! nlohmann::json_abi_v3_11_2::detail::is_json_iterator_of<nlohmann::json_abi_v3_11_2::basic_json<>, typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value)), std::integral_constant<bool, true>, std::integral_constant<bool, false> >::type::value, int>::type <anonymous> = <missing>]'
<source>:24606:9:   required from here
<source>:3911:33: warning: 'nlohmann::json_abi_v3_11_2::json_pointer<RefStringType>::operator string_t() const [with RefStringType = std::__cxx11::basic_string<char>; string_t = std::__cxx11::basic_string<char>]' is deprecated: Since 3.11.0; use to_string() [-Wdeprecated-declarations]
 3911 | decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:13765:5: note: declared here
13765 |     operator string_t() const
      |     ^~~~~~~~
<source>:3912:33: warning: 'nlohmann::json_abi_v3_11_2::json_pointer<RefStringType>::operator string_t() const [with RefStringType = std::__cxx11::basic_string<char>; string_t = std::__cxx11::basic_string<char>]' is deprecated: Since 3.11.0; use to_string() [-Wdeprecated-declarations]
 3912 | decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:13765:5: note: declared here
13765 |     operator string_t() const
      |     ^~~~~~~~
<source>:3911:33: warning: 'nlohmann::json_abi_v3_11_2::json_pointer<RefStringType>::operator string_t() const [with RefStringType = std::__cxx11::basic_string<char>; string_t = std::__cxx11::basic_string<char>]' is deprecated: Since 3.11.0; use to_string() [-Wdeprecated-declarations]
 3911 | decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:13765:5: note: declared here
13765 |     operator string_t() const
      |     ^~~~~~~~
<source>:3912:33: warning: 'nlohmann::json_abi_v3_11_2::json_pointer<RefStringType>::operator string_t() const [with RefStringType = std::__cxx11::basic_string<char>; string_t = std::__cxx11::basic_string<char>]' is deprecated: Since 3.11.0; use to_string() [-Wdeprecated-declarations]
 3912 | decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:13765:5: note: declared here
13765 |     operator string_t() const
      |     ^~~~~~~~

Compiler and operating system

GCC (tried 12.2 back to 4.8)

Library version

3.11.2

Validation

doj commented 1 year ago

I have the same problem. I am compiling with gcc 7.5.0 and c++11. When I disable deprecated warnings with -Wno-deprecated-declarations then the code compiles without issues. But it seems that this was a desired change to deprecate using a json_pointer with the at() and operator[] functions?

jmml97 commented 1 year ago

I am also having this problem.

jmml97 commented 1 year ago

My problem was that I was using nlohmann::json_pointer<nlohmann::json> {"path/here"} instead of nlohmann::json::json_pointer("path/here").

Changing all the uses from one version to the other solved the problem.

coolo commented 1 year ago

Is there any workaround for this problem? I hate adding -Wno-deprecated-declarations

kunlinyu commented 10 months ago

I have same issue. I am using v3.11.3. this is the message:

In file included from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/exceptions.hpp:25,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/conversions/from_json.hpp:23,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/adl_serializer.hpp:14,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:34,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/json-schema-validator/src/nlohmann/json-schema.hpp:24,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:16:
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp: In instantiation of 'struct nlohmann::json_abi_v3_11_3::detail::is_comparable<std::less<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char>, nlohmann::json_abi_v3_11_3::json_pointer<std::__cxx11::basic_string<char> >&, void>':
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp:581:31:   required by substitution of 'template<class KeyType, typename std::enable_if<typename std::conditional<(typename std::conditional<(((nlohmann::json_abi_v3_11_3::detail::is_comparable<std::less<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char>, KeyType, void>::value && (!(true && std::is_same<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, std::__cxx11::basic_string<char> >::value))) && ((! true) || std::integral_constant<bool, false>::value)) && (! nlohmann::json_abi_v3_11_3::detail::is_specialization_of<nlohmann::json_abi_v3_11_3::json_pointer, typename std::remove_cv<typename std::remove_reference<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::type>::type>::value)), std::integral_constant<bool, true>, std::integral_constant<bool, false> >::type::value && (! nlohmann::json_abi_v3_11_3::detail::is_json_iterator_of<nlohmann::json_abi_v3_11_3::basic_json<>, typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value)), std::integral_constant<bool, true>, std::integral_constant<bool, false> >::type::value, int>::type <anonymous> > const value_type& nlohmann::json_abi_v3_11_3::basic_json<>::at<KeyType, <anonymous> >(KeyType&&) const [with KeyType = nlohmann::json_abi_v3_11_3::json_pointer<std::__cxx11::basic_string<char> >&; typename std::enable_if<typename std::conditional<(typename std::conditional<(((nlohmann::json_abi_v3_11_3::detail::is_comparable<std::less<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char>, KeyType, void>::value && (!(true && std::is_same<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, std::__cxx11::basic_string<char> >::value))) && ((! true) || std::integral_constant<bool, false>::value)) && (! nlohmann::json_abi_v3_11_3::detail::is_specialization_of<nlohmann::json_abi_v3_11_3::json_pointer, typename std::remove_cv<typename std::remove_reference<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::type>::type>::value)), std::integral_constant<bool, true>, std::integral_constant<bool, false> >::type::value && (! nlohmann::json_abi_v3_11_3::detail::is_json_iterator_of<nlohmann::json_abi_v3_11_3::basic_json<>, typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value)), std::integral_constant<bool, true>, std::integral_constant<bool, false> >::type::value, int>::type <anonymous> = <missing>]'
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:4756:43:   required from 'void nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::patch_inplace(const nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>&) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::json_abi_v3_11_3::adl_serializer; BinaryType = std::vector<unsigned char>; CustomBaseClass = void]'
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:4973:16:   required from 'nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass> nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::patch(const nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>&) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::json_abi_v3_11_3::adl_serializer; BinaryType = std::vector<unsigned char>; CustomBaseClass = void]'
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:61:32:   required from here
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp:568:33: warning: 'nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::operator nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::string_t() const [with RefStringType = std::__cxx11::basic_string<char>; nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::string_t = std::__cxx11::basic_string<char>]' is deprecated: Since 3.11.0; use to_string() [-Wdeprecated-declarations]
  568 | decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:50,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/json-schema-validator/src/nlohmann/json-schema.hpp:24,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:16:
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/json_pointer.hpp:81:5: note: declared here
   81 |     operator string_t() const
      |     ^~~~~~~~
In file included from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/exceptions.hpp:25,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/conversions/from_json.hpp:23,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/adl_serializer.hpp:14,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:34,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/json-schema-validator/src/nlohmann/json-schema.hpp:24,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:16:
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp:569:33: warning: 'nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::operator nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::string_t() const [with RefStringType = std::__cxx11::basic_string<char>; nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::string_t = std::__cxx11::basic_string<char>]' is deprecated: Since 3.11.0; use to_string() [-Wdeprecated-declarations]
  569 | decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:50,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/json-schema-validator/src/nlohmann/json-schema.hpp:24,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:16:
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/json_pointer.hpp:81:5: note: declared here
   81 |     operator string_t() const
      |     ^~~~~~~~
In file included from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/exceptions.hpp:25,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/conversions/from_json.hpp:23,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/adl_serializer.hpp:14,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:34,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/json-schema-validator/src/nlohmann/json-schema.hpp:24,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:16:
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp:568:33: warning: 'nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::operator nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::string_t() const [with RefStringType = std::__cxx11::basic_string<char>; nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::string_t = std::__cxx11::basic_string<char>]' is deprecated: Since 3.11.0; use to_string() [-Wdeprecated-declarations]
  568 | decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:50,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/json-schema-validator/src/nlohmann/json-schema.hpp:24,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:16:
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/json_pointer.hpp:81:5: note: declared here
   81 |     operator string_t() const
      |     ^~~~~~~~
In file included from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/exceptions.hpp:25,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/conversions/from_json.hpp:23,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/adl_serializer.hpp:14,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:34,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/json-schema-validator/src/nlohmann/json-schema.hpp:24,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:16:
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp:569:33: warning: 'nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::operator nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::string_t() const [with RefStringType = std::__cxx11::basic_string<char>; nlohmann::json_abi_v3_11_3::json_pointer<RefStringType>::string_t = std::__cxx11::basic_string<char>]' is deprecated: Since 3.11.0; use to_string() [-Wdeprecated-declarations]
  569 | decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/json.hpp:50,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/json-schema-validator/src/nlohmann/json-schema.hpp:24,
                 from /mnt/c/Users/yukunlin/Documents/indoorjson-cpp/src/main.cpp:16:
/mnt/c/Users/yukunlin/Documents/indoorjson-cpp/dependencies/nlohmann_json/include/nlohmann/detail/json_pointer.hpp:81:5: note: declared here
   81 |     operator string_t() const
      |     ^~~~~~~~
kaylum commented 8 months ago

FWIW with g++ 11.4 the warnings are present with -std=c++11 but not -std=c++14.

Doesn't help me as my code base is currently stuck on c++11 but noting in case it is of use to anyone else.