]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix -Wmismatched-delete bug in std::unique_ptr test
authorJonathan Wakely <jwakely@redhat.com>
Tue, 30 Sep 2025 11:10:15 +0000 (12:10 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 1 Oct 2025 13:33:59 +0000 (14:33 +0100)
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>
libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/93562.cc

index 95df7afb9644e5d01a82b7d9e9a1d30bdf4edaf3..044357888ea659e10a34d4f2c81a4a8ec86e4252 100644 (file)
@@ -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: