]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/93562.cc
1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++11 } }
21 #include <testsuite_hooks.h>
25 // This function isn't called, we just need to check it compiles.
27 test01(std::unique_ptr
<incomplete
>& p1
, std::unique_ptr
<incomplete
>& p2
)
34 // This function isn't called, we just need to check it compiles.
36 test02(std::unique_ptr
<incomplete
[]>& p1
, std::unique_ptr
<incomplete
[]>& p2
)
47 Deleter
& operator=(const Deleter
&) = delete;
49 void operator()(int* p
) const noexcept
{ delete p
; }
52 friend void swap(Deleter
& lhs
, Deleter
& rhs
) noexcept
53 { std::swap(lhs
.id
, rhs
.id
); }
58 static_assert(!std::is_move_assignable
<Deleter
>::value
, "not assignable");
59 #if __cplusplus >= 201703L
60 static_assert(std::is_swappable_v
<Deleter
>, "but swappable");
67 std::unique_ptr
<int, A::Deleter
> p1(new int(1), { -1 });
68 std::unique_ptr
<int, A::Deleter
> p2(new int(2), { -2 });
69 int* const pi1
= p1
.get();
70 int* const pi2
= p2
.get();
71 // This type must swappable even though the deleter is not move-assignable:
73 VERIFY(p1
.get() == pi2
);
74 VERIFY(p1
.get_deleter().id
== -2);
75 VERIFY(p2
.get() == pi1
);
76 VERIFY(p2
.get_deleter().id
== -1);
82 std::unique_ptr
<int[], A::Deleter
> p1(new int[1]{1}, { -1 });
83 std::unique_ptr
<int[], A::Deleter
> p2(new int[2]{2, 2}, { -2 });
84 int* const pi1
= p1
.get();
85 int* const pi2
= p2
.get();
86 // This type must swappable even though the deleter is not move-assignable:
88 VERIFY(p1
.get() == pi2
);
89 VERIFY(p1
.get_deleter().id
== -2);
90 VERIFY(p2
.get() == pi1
);
91 VERIFY(p2
.get_deleter().id
== -1);