diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index d0c947bba..8fb4c332c 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -881,7 +881,7 @@ class binary_writer for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i) { oa->write_character(to_char_type(bjdata_draft3 ? 'B' : 'U')); - oa->write_character(j.m_data.m_value.binary->data()[i]); + oa->write_character(to_char_type(j.m_data.m_value.binary->data()[i])); } } @@ -1634,7 +1634,9 @@ class binary_writer }; string_t key = "_ArrayType_"; - auto it = bjdtype.find(static_cast(value.at(key))); + // use get() instead of static_cast to avoid an + // ambiguous conversion under explicit instantiation on C++17 (see #4825) + auto it = bjdtype.find(value.at(key).template get()); if (it == bjdtype.end()) { return true; diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 53a53d76f..e3bd3ea0b 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4302,7 +4302,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } }; - data m_data = {}; + data m_data = {}; // NOLINT(readability-redundant-member-init) #if JSON_DIAGNOSTICS /// a pointer to a parent value (for debugging purposes) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 1fc0a5576..1a2b3d357 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -17172,7 +17172,7 @@ class binary_writer for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i) { oa->write_character(to_char_type(bjdata_draft3 ? 'B' : 'U')); - oa->write_character(j.m_data.m_value.binary->data()[i]); + oa->write_character(to_char_type(j.m_data.m_value.binary->data()[i])); } } @@ -17925,7 +17925,9 @@ class binary_writer }; string_t key = "_ArrayType_"; - auto it = bjdtype.find(static_cast(value.at(key))); + // use get() instead of static_cast to avoid an + // ambiguous conversion under explicit instantiation on C++17 (see #4825) + auto it = bjdtype.find(value.at(key).template get()); if (it == bjdtype.end()) { return true; @@ -24916,7 +24918,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } }; - data m_data = {}; + data m_data = {}; // NOLINT(readability-redundant-member-init) #if JSON_DIAGNOSTICS /// a pointer to a parent value (for debugging purposes) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index b4fc699c8..bf2d87767 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -66,7 +66,17 @@ using ordered_json = nlohmann::ordered_json; #endif #endif +///////////////////////////////////////////////////////////////////// +// for #4825 - explicitly instantiating basic_json must compile; this +// forces instantiation of binary_writer::write_bjdata_ndarray, whose +// static_cast was ambiguous under explicit instantiation on +// C++17. Merely compiling this translation unit is the regression test. +///////////////////////////////////////////////////////////////////// +template class nlohmann::basic_json<>; + +///////////////////////////////////////////////////////////////////// // for #4440 +///////////////////////////////////////////////////////////////////// #if JSON_HAS_RANGES == 1 #include #endif