| 1 |
// { dg-do compile { target c++23 } } |
| 2 |
|
| 3 |
#include <memory> |
| 4 |
#include <testsuite_hooks.h> |
| 5 |
|
| 6 |
constexpr bool |
| 7 |
test_move() |
| 8 |
{ |
| 9 |
std::unique_ptr<int> p1(new int(2)); |
| 10 |
std::unique_ptr<int> p2; |
| 11 |
p2 = std::move(p1); |
| 12 |
VERIFY( *p2 == 2 ); |
| 13 |
std::unique_ptr<int[]> a1(new int[]{0, 1, 2}); |
| 14 |
std::unique_ptr<int[]> a2; |
| 15 |
a2 = std::move(a1); |
| 16 |
VERIFY( a2[2] == 2 ); |
| 17 |
|
| 18 |
return true; |
| 19 |
} |
| 20 |
static_assert( test_move() ); |
| 21 |
|
| 22 |
constexpr bool |
| 23 |
test_convert() |
| 24 |
{ |
| 25 |
std::unique_ptr<int> p1(new int(2)); |
| 26 |
std::unique_ptr<const int> p2; |
| 27 |
p2 = std::move(p1); |
| 28 |
VERIFY( *p2 == 2 ); |
| 29 |
std::unique_ptr<int[]> a1(new int[]{0, 1, 2}); |
| 30 |
std::unique_ptr<const int[]> a2; |
| 31 |
a2 = std::move(a1); |
| 32 |
VERIFY( a2[2] == 2 ); |
| 33 |
|
| 34 |
return true; |
| 35 |
} |
| 36 |
static_assert( test_convert() ); |
| 37 |
|
| 38 |
constexpr bool |
| 39 |
test_null() |
| 40 |
{ |
| 41 |
std::unique_ptr<int> p(new int(2)); |
| 42 |
p = nullptr; |
| 43 |
VERIFY( !p ); |
| 44 |
p = nullptr; |
| 45 |
return true; |
| 46 |
} |
| 47 |
static_assert( test_null() ); |