Repository navigation
Template instantiation of nlohmann::basic_json<> fails on C++17 #4825
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 constructorCompiler 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
developbranch is used. - I can successfully compile and run the unit tests.
Activity
docs: replace unnecessary `.template get<...>` with `.get<...>` in RE…
github-actions commentedon Sep 17, 2025
This issue has been marked as stale because it has been open for 90 days without activity. If this issue is still relevant, please add a comment or remove the "stale" label. Otherwise, it will be closed in 10 days. Thank you for helping us prioritize our work!
github-actions commentedon Sep 28, 2025
This issue has been closed after being marked as stale for 10 days without any further activity. If this was done in error or the issue is still relevant, please feel free to reopen it or create a new issue. We appreciate your understanding and contributions.
docs: replace unnecessary `.template get<...>` with `.get<...>` in RE…
docs: replace unnecessary `.template get<...>` with `.get<...>` in RE…
docs: replace unnecessary `.template get<...>` with `.get<...>` in RE…
Move the explicit basic_json instantiation into its own test file
Add BON8 support (#2998)