nlohmann / json

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

flatten() function does not compile if an alternative string type is used #4019

Open FonsDC opened 1 year ago

FonsDC commented 1 year ago

Description

The flatten() function does not compile if an alternative string type is used, like in the unit-alt-string.cpp unit test

Reproduction steps

Add this test section to unit-alt-string.cpp and build the unit tests:

SECTION("flatten")
{
  alt_json j = alt_json::parse(R"({"foo": ["bar", "baz"]})");
  auto j2 = j.flatten();
}

Expected vs. actual results

Compilation fails. See error output below.

Minimal code example

See "Reproduction steps"

Error messages

[  4%] Building CXX object tests/CMakeFiles/test-alt-string_cpp11.dir/src/unit-alt-string.cpp.o
In file included from /_install/json-3.11.2/include/nlohmann/json.hpp:50,
                 from /_install/json-3.11.2/tests/src/unit-alt-string.cpp:12:
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp: In instantiation of ‘static void nlohmann::json_abi_v3_11_2::json_pointer<RefStringType>::flatten(const string_t&, const BasicJsonType&, BasicJsonType&) [with BasicJsonType = nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, alt_string, bool, long int, long unsigned int, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer>; RefStringType = alt_string; nlohmann::json_abi_v3_11_2::json_pointer<RefStringType>::string_t = alt_string]’:
/_install/json-3.11.2/include/nlohmann/json.hpp:4646:30:   required from ‘nlohmann::json_abi_v3_11_2::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType> nlohmann::json_abi_v3_11_2::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::flatten() const [with ObjectType = std::map; ArrayType = std::vector; StringType = alt_string; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::json_abi_v3_11_2::adl_serializer; BinaryType = std::vector<unsigned char>]’
/_install/json-3.11.2/tests/src/unit-alt-string.cpp:331:28:   required from here
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp:753:32: error: no matching function for call to ‘nlohmann::json_abi_v3_11_2::json_pointer<alt_string>::flatten(std::__cxx11::basic_string<char>, __gnu_cxx::__alloc_traits<std::allocator<nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, alt_string, bool, long int, long unsigned int, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer> >, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, alt_string, bool, long int, long unsigned int, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer> >::value_type&, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, alt_string, bool, long int, long unsigned int, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer>&)’
  753 |                         flatten(detail::concat(reference_string, '/', std::to_string(i)),
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  754 |                                 value.m_value.array->operator[](i), result);
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp:735:17: note: candidate: ‘template<class BasicJsonType> static void nlohmann::json_abi_v3_11_2::json_pointer<RefStringType>::flatten(const string_t&, const BasicJsonType&, BasicJsonType&) [with BasicJsonType = BasicJsonType; RefStringType = alt_string]’
  735 |     static void flatten(const string_t& reference_string,
      |                 ^~~~~~~
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp:735:17: note:   template argument deduction/substitution failed:
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp:753:32: note:   cannot convert ‘nlohmann::json_abi_v3_11_2::detail::concat(Args&& ...) [with OutStringType = std::__cxx11::basic_string<char>; Args = {const alt_string&, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >}]('/', std::__cxx11::to_string(long unsigned int)())’ (type ‘std::__cxx11::basic_string<char>’) to type ‘const string_t&’ {aka ‘const alt_string&’}
  753 |                         flatten(detail::concat(reference_string, '/', std::to_string(i)),
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  754 |                                 value.m_value.array->operator[](i), result);
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp:772:32: error: no matching function for call to ‘nlohmann::json_abi_v3_11_2::json_pointer<alt_string>::flatten(std::__cxx11::basic_string<char>, const nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, alt_string, bool, long int, long unsigned int, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer>&, nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, alt_string, bool, long int, long unsigned int, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer>&)’
  772 |                         flatten(detail::concat(reference_string, '/', detail::escape(element.first)), element.second, result);
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp:735:17: note: candidate: ‘template<class BasicJsonType> static void nlohmann::json_abi_v3_11_2::json_pointer<RefStringType>::flatten(const string_t&, const BasicJsonType&, BasicJsonType&) [with BasicJsonType = BasicJsonType; RefStringType = alt_string]’
  735 |     static void flatten(const string_t& reference_string,
      |                 ^~~~~~~
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp:735:17: note:   template argument deduction/substitution failed:
/_install/json-3.11.2/include/nlohmann/detail/json_pointer.hpp:772:32: note:   cannot convert ‘nlohmann::json_abi_v3_11_2::detail::concat(Args&& ...) [with OutStringType = std::__cxx11::basic_string<char>; Args = {const alt_string&, char, alt_string}]('/', nlohmann::json_abi_v3_11_2::detail::escape(StringType) [with StringType = alt_string]())’ (type ‘std::__cxx11::basic_string<char>’) to type ‘const string_t&’ {aka ‘const alt_string&’}
  772 |                         flatten(detail::concat(reference_string, '/', detail::escape(element.first)), element.second, result);
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gmake[2]: *** [tests/CMakeFiles/test-alt-string_cpp11.dir/build.make:76: tests/CMakeFiles/test-alt-string_cpp11.dir/src/unit-alt-string.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1291: tests/CMakeFiles/test-alt-string_cpp11.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

Compiler and operating system

Operating system: Rocky Linux release 8.7

Library version

3.11.2

Validation