diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index d0c947bba9..8fb4c332c4 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 fefc750fd1..c5d7c1944e 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4280,7 +4280,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 0e23b09a61..b7e7445d82 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -17076,7 +17076,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])); } } @@ -17829,7 +17829,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; @@ -24798,7 +24800,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 b4fc699c85..bf2d877673 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