-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Description
template class nlohmann::basic_json<>;
leads to a compilation error "ambigious static_caststd::string" inside binary_writer::write_bjdata_ndarray
.
Observed on bcc64 (Clang 5.0 with changes that doesn't seem relevant to the issue), the exact message provided below.
Reproduction steps
On RAD Studio 11, creating a simple 64-bit console application with the following added to the beginning of the .cpp
file
#include "json.hpp"
template class nlohmann::basic_json<>;
reproduces the issue. Presumably, the same will happen when using Clang 5.0 with -std=c++17 (or any other compiler, the core issue seems to be the same ambiguity between std::string and std::string_view that lead to a number of other issues).
Replacing
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
with
string_t tmp = value.at(key);
auto it = bjdtype.find(tmp);
tmp = string_t();
in write_bjdata_ndarray()
fixes the issue.
Expected vs. actual results
My expectation was that instantiating all methods of library classes would not lead to compilation errors - if a method exists at all on C++17, it should compile.
Minimal code example
Error messages
[bcc64 Error] json.hpp(16578): ambiguous conversion for static_cast from 'const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, nlohmann::json_abi_v3_11_2::basic_json<>, std::less<void>, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, nlohmann::json_abi_v3_11_2::basic_json<> > > >::mapped_type' (aka 'const nlohmann::json_abi_v3_11_2::basic_json<>') to 'nlohmann::json_abi_v3_11_2::detail::binary_writer<nlohmann::json_abi_v3_11_2::basic_json<>, unsigned char>::string_t' (aka 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >')
[bcc64 Hint] json.hpp(15843): in instantiation of member function 'nlohmann::json_abi_v3_11_2::detail::binary_writer<nlohmann::json_abi_v3_11_2::basic_json<>, unsigned char>::write_bjdata_ndarray' requested here
[bcc64 Hint] json.hpp(23520): in instantiation of member function 'nlohmann::json_abi_v3_11_2::detail::binary_writer<nlohmann::json_abi_v3_11_2::basic_json<>, unsigned char>::write_ubjson' requested here
[bcc64 Hint] xstring(962): candidate constructor
[bcc64 Hint] xstring(798): candidate constructor
[bcc64 Hint] xstring(864): candidate constructor
Compiler and operating system
Windows 10 / RAD toolchain (bcc64, "Clang-enhanced" compiler)
Library version
3.11.2
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.