From 17d6fa753bdab3c8a5ecdaa42c257ac1beb53bfa Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 31 Aug 2026 09:24:25 +0000 Subject: [PATCH] Give the custom container types only the constructors the library uses The three container types in the new tests inherited every constructor of their base with using Base::Base. That asks for more than the test needs: the library builds an object or an array by default construction, by copy or move, and -- when converting between two basic_json types or from an initializer list -- from an iterator range. Declaring those directly makes the requirement visible in the test, and keeps object types out of a corner where a compiler has to declare std::map's whole constructor set for a derived class while basic_json is still incomplete. Signed-off-by: Niels Lohmann --- tests/src/unit-custom-array-type.cpp | 6 +++++- tests/src/unit-custom-object-type.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/src/unit-custom-array-type.cpp b/tests/src/unit-custom-array-type.cpp index df66340a1..00606c6e0 100644 --- a/tests/src/unit-custom-array-type.cpp +++ b/tests/src/unit-custom-array-type.cpp @@ -30,7 +30,11 @@ template> class vector_without_at : public std::vector { public: - using std::vector::vector; + vector_without_at() = default; + + // the array of an initializer list is built from a range + template + vector_without_at(InputIt first, InputIt last) : std::vector(first, last) {} void at() = delete; }; diff --git a/tests/src/unit-custom-object-type.cpp b/tests/src/unit-custom-object-type.cpp index 79b2ac6cc..c27c5ea23 100644 --- a/tests/src/unit-custom-object-type.cpp +++ b/tests/src/unit-custom-object-type.cpp @@ -35,7 +35,12 @@ template struct no_key_compare_map : std::map { using base_t = std::map; - using base_t::base_t; + + no_key_compare_map() = default; + + // converting between two basic_json types builds the object from a range + template + no_key_compare_map(InputIt first, InputIt last) : base_t(first, last) {} // shadows base_t::key_compare, which is a type; never defined or called void key_compare(); @@ -49,7 +54,6 @@ template struct void_erase_map : std::map { using base_t = std::map; - using base_t::base_t; using iterator = typename base_t::iterator; using base_t::erase;