diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index dc7fd4007..491bb9873 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -484,7 +484,14 @@ inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence< // keeps a string type constructible from 0 from selecting operator[](key) const bool is_member = element.is_array() && element.size() == 2 && element[static_cast(0)].is_string(); - j = is_member ? BasicJsonType::object({std::move(element)}) : BasicJsonType::array({std::move(element)}); + if (is_member) + { + j = BasicJsonType::object({std::move(element)}); + } + else + { + j = BasicJsonType::array({std::move(element)}); + } } #endif diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f6692da11..c23d8b89f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -6778,7 +6778,14 @@ inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence< // keeps a string type constructible from 0 from selecting operator[](key) const bool is_member = element.is_array() && element.size() == 2 && element[static_cast(0)].is_string(); - j = is_member ? BasicJsonType::object({std::move(element)}) : BasicJsonType::array({std::move(element)}); + if (is_member) + { + j = BasicJsonType::object({std::move(element)}); + } + else + { + j = BasicJsonType::array({std::move(element)}); + } } #endif diff --git a/tests/src/unit-brace-init-copy-semantics.cpp b/tests/src/unit-brace-init-copy-semantics.cpp index 63631de6e..1ee0c6607 100644 --- a/tests/src/unit-brace-init-copy-semantics.cpp +++ b/tests/src/unit-brace-init-copy-semantics.cpp @@ -35,7 +35,8 @@ TEST_CASE("JSON_BRACE_INIT_COPY_SEMANTICS") SECTION("the macro is part of the ABI tag") { const std::string ns = STRINGIZE(NLOHMANN_JSON_NAMESPACE); - CHECK(ns.find("json_abi_bics") != std::string::npos); + // other tags may come before it, e.g. json_abi_ldvcmp_bics + CHECK(ns.find("_bics") != std::string::npos); } SECTION("single-element brace initialization copies the element (#5074)") @@ -156,7 +157,7 @@ TEST_CASE("JSON_BRACE_INIT_COPY_SEMANTICS") SECTION("items()") { json j_obj = {{"key", 1}}; - for (auto& el : j_obj.items()) + for (const auto& el : j_obj.items()) { json const j = el; CHECK(j.dump() == "{\"key\":1}");