From 9a35702da80b78ef1c157434a68f1d17a94328ba Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 13 Oct 2021 20:34:17 +0200 Subject: [PATCH] :rewind: remove "fix" that caused #3077 --- include/nlohmann/json.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- test/src/unit-regression2.cpp | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index b140577f2c..19c6011835 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3069,7 +3069,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( JSONSerializer::from_json(std::declval(), std::declval()))) { - ValueType ret{}; + ValueType ret; JSONSerializer::from_json(*this, ret); return ret; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 25c6983b04..e41ff9ec94 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20556,7 +20556,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( JSONSerializer::from_json(std::declval(), std::declval()))) { - ValueType ret{}; + ValueType ret; JSONSerializer::from_json(*this, ret); return ret; } diff --git a/test/src/unit-regression2.cpp b/test/src/unit-regression2.cpp index cf74297825..e84b8bd81e 100644 --- a/test/src/unit-regression2.cpp +++ b/test/src/unit-regression2.cpp @@ -189,6 +189,32 @@ template class my_allocator : public std::allocator {}; +///////////////////////////////////////////////////////////////////// +// for #3077 +///////////////////////////////////////////////////////////////////// + +class FooAlloc +{}; + +class Foo +{ + public: + explicit Foo(const FooAlloc& = FooAlloc()) : value(false) {} + + bool value; +}; + +class FooBar +{ + public: + Foo foo; +}; + +inline void from_json(const nlohmann::json& j, FooBar& fb) +{ + j.at("value").get_to(fb.foo.value); +} + TEST_CASE("regression tests 2") { SECTION("issue #1001 - Fix memory leak during parser callback") @@ -695,6 +721,14 @@ TEST_CASE("regression tests 2") json k = json::from_cbor(my_vector); CHECK(j == k); } + + SECTION("issue #3077 - explicit constructor with default does not compile") + { + json j; + j[0]["value"] = true; + std::vector foo; + j.get_to(foo); + } } DOCTEST_CLANG_SUPPRESS_WARNING_POP