Write out what the defaulted constructor of no_key_compare_map implied

ci_test_gcc builds with -Weffc++, which asks for data to be initialized in a
member initialization list; a defaulted default constructor does not do that:

  error: 'no_key_compare_map<...>::data' should be initialized in the member
         initialization list                              [-Werror=effc++]

Writing the constructor out satisfies that but drops the exception
specification the defaulted one carried, which -Wnoexcept then objects to
where the standard library takes noexcept(construct(...)). Declare it the way
the defaulted constructor was: noexcept when the wrapped map's default
constructor is.

This is the cost of composition -- inheritance carried std::map's exception
specifications and initialization for free, and forwarding by hand has to
restate them.

Checked with the repository's own GCC warning set from cmake/gcc_flags.cmake,
all 346 flags, at C++11, C++17 and C++20: no diagnostics for this file, nor
for the two custom container translation units that were disabled while the
MSVC failure was narrowed down and are built again now.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018hxZxz8svM54c6ATEvXp5E
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-09-02 07:55:39 +00:00
co-authored by Claude Opus 5
parent 207db0f124
commit 216f57f43b
+6 -1
View File
@@ -53,7 +53,12 @@ class no_key_compare_map
using iterator = typename map_t::iterator;
using const_iterator = typename map_t::const_iterator;
no_key_compare_map() = default;
// -Weffc++ asks for the member to be initialized in the member
// initialization list, which a defaulted constructor does not do; the
// exception specification a defaulted one would have carried has to be
// written out as well, or -Wnoexcept objects where the standard library
// takes noexcept(construct(...))
no_key_compare_map() noexcept(std::is_nothrow_default_constructible<map_t>::value) : data() {}
// converting between two basic_json types builds the object from a range
template<class InputIt>