Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 2 tasks
FonsDC opened this issue Apr 26, 2023 · 1 comment · Fixed by #4613
Closed
1 of 2 tasks

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

FonsDC opened this issue Apr 26, 2023 · 1 comment · Fixed by #4613
Labels
confirmed good first issue kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@FonsDC
Copy link

FonsDC commented Apr 26, 2023

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

@nlohmann
Copy link
Owner

I can confirm the issue. Probably replacing std::to_string with detail::to_string can help - or be the start of a solution.

@hnampally hnampally mentioned this issue Jan 20, 2025
5 tasks
@nlohmann nlohmann linked a pull request Jan 22, 2025 that will close this issue
5 tasks
@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jan 22, 2025
@nlohmann nlohmann added this to the Release 3.11.4 milestone Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed good first issue kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants