From 207db0f1248f4fdeca425ee4546409e3fda1be38 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 2 Sep 2026 07:48:21 +0000 Subject: [PATCH] Declare no_key_compare_map's accessors noexcept The GCC C++20 job builds with -Wnoexcept and -Werror, and the standard library takes noexcept(c.begin()) and noexcept(c.end()) in ranges_base.h and range_access.h. Forwarding to std::map without repeating its noexcept made those expressions false, which the warning reports as an error: error: noexcept-expression evaluates to 'false' because of a call to no_key_compare_map<...>::begin() [-Werror=noexcept] note: but ... does not throw; perhaps it should be declared 'noexcept' Give the accessors the exception specification of what they forward to. std::map declares begin, end, cbegin, cend, empty, size, max_size, and clear noexcept, so the wrapper does too. swap is left alone: std::map's is only conditionally noexcept, and nothing asks for it. void_erase_map is unaffected because it still derives from std::map and inherits accessors that already carry the specification. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_018hxZxz8svM54c6ATEvXp5E Signed-off-by: Niels Lohmann --- tests/src/unit-custom-object-type.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/src/unit-custom-object-type.cpp b/tests/src/unit-custom-object-type.cpp index ffdf94fa5..62302725c 100644 --- a/tests/src/unit-custom-object-type.cpp +++ b/tests/src/unit-custom-object-type.cpp @@ -59,44 +59,44 @@ class no_key_compare_map template no_key_compare_map(InputIt first, InputIt last) : data(first, last) {} - iterator begin() + iterator begin() noexcept { return data.begin(); } - iterator end() + iterator end() noexcept { return data.end(); } - const_iterator begin() const + const_iterator begin() const noexcept { return data.begin(); } - const_iterator end() const + const_iterator end() const noexcept { return data.end(); } - const_iterator cbegin() const + const_iterator cbegin() const noexcept { return data.cbegin(); } - const_iterator cend() const + const_iterator cend() const noexcept { return data.cend(); } - bool empty() const + bool empty() const noexcept { return data.empty(); } - size_type size() const + size_type size() const noexcept { return data.size(); } - size_type max_size() const + size_type max_size() const noexcept { return data.max_size(); } - void clear() + void clear() noexcept { data.clear(); }