[gcc r16-4160] libstdc++: Fix -Wmismatched-delete bug in std::unique_ptr test
Jonathan Wakely
redi@gcc.gnu.org
Wed Oct 1 13:37:27 GMT 2025
https://gcc.gnu.org/g:d5c5c1a136142e3cffe3e30c333c84c153fcdb5d
commit r16-4160-gd5c5c1a136142e3cffe3e30c333c84c153fcdb5d
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Sep 30 12:10:15 2025 +0100
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 <tkaminsk@redhat.com>
Diff:
---
.../20_util/unique_ptr/modifiers/93562.cc | 25 ++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
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<Deleter>::value, "not assignable");
+#if __cplusplus >= 201703L
+ static_assert(std::is_swappable_v<Deleter>, "but swappable");
+#endif
+} // namespace B
+
void
test04()
{
- std::unique_ptr<int[], A::Deleter> p1(new int[1]{1}, { -1 });
- std::unique_ptr<int[], A::Deleter> p2(new int[2]{2, 2}, { -2 });
+ std::unique_ptr<int[], B::Deleter> p1(new int[1]{1}, { -1 });
+ std::unique_ptr<int[], B::Deleter> 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:
More information about the Libstdc++-cvs
mailing list