From: Jonathan Wakely Date: Tue, 30 Sep 2025 11:10:15 +0000 (+0100) Subject: libstdc++: Fix -Wmismatched-delete bug in std::unique_ptr test X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d5c5c1a136142e3cffe3e30c333c84c153fcdb5d;p=thirdparty%2Fgcc.git libstdc++: Fix -Wmismatched-delete bug in std::unique_ptr test libstdc++-v3/ChangeLog: * testsuite/20_util/unique_ptr/modifiers/93562.cc: Define a separate deleter for array cases. Reviewed-by: Tomasz KamiƄski --- diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/93562.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/93562.cc index 95df7afb9644..044357888ea6 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/93562.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/93562.cc @@ -76,11 +76,32 @@ test03() VERIFY(p2.get_deleter().id == -1); } +namespace B +{ + struct Deleter + { + Deleter& operator=(const Deleter&) = delete; + + void operator()(int* p) const noexcept { delete[] p; } + + // found by ADL + friend void swap(Deleter& lhs, Deleter& rhs) noexcept + { std::swap(lhs.id, rhs.id); } + + int id; + }; + + static_assert(!std::is_move_assignable::value, "not assignable"); +#if __cplusplus >= 201703L + static_assert(std::is_swappable_v, "but swappable"); +#endif +} // namespace B + void test04() { - std::unique_ptr p1(new int[1]{1}, { -1 }); - std::unique_ptr p2(new int[2]{2, 2}, { -2 }); + std::unique_ptr p1(new int[1]{1}, { -1 }); + std::unique_ptr p2(new int[2]{2, 2}, { -2 }); int* const pi1 = p1.get(); int* const pi2 = p2.get(); // This type must swappable even though the deleter is not move-assignable: