Skip to content

Template instantiation of nlohmann::basic_json<> fails on C++17 #4825

Closed

Description

@B-N-O

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

Activity

  1. added a commit that references this issue on Sep 12, 2025
    2f2352d
  2. github-actions commented on Sep 17, 2025

    @github-actions

    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!

  3. added
    state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated
    on Sep 17, 2025
  4. github-actions commented on Sep 28, 2025

    @github-actions

    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.

  5. added 2 commits that reference this issue on Oct 1, 2025
    b626754
    3ab4582
  6. added a commit that references this issue on Oct 23, 2025
    41a0fee
  7. added
    solution: proposed fixa fix for the issue has been proposed and waits for confirmation
    and removed
    state: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated
    on Jun 30, 2026
  8. added this to the Release 3.12.1 milestone on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugsolution: proposed fixa fix for the issue has been proposed and waits for confirmation

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions