| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// <memory> |
| 10 |
|
| 11 |
// unique_ptr |
| 12 |
|
| 13 |
// Test unique_ptr move assignment |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
#include <cassert> |
| 17 |
|
| 18 |
#include "test_macros.h" |
| 19 |
#include "unique_ptr_test_helper.h" |
| 20 |
|
| 21 |
// test assignment from null |
| 22 |
|
| 23 |
template <bool IsArray> |
| 24 |
TEST_CONSTEXPR_CXX23 void test_basic() { |
| 25 |
typedef typename std::conditional<IsArray, A[], A>::type VT; |
| 26 |
const int expect_alive = IsArray ? 5 : 1; |
| 27 |
{ |
| 28 |
std::unique_ptr<VT> s2(newValue<VT>(expect_alive)); |
| 29 |
if (!TEST_IS_CONSTANT_EVALUATED) |
| 30 |
assert(A::count == expect_alive); |
| 31 |
s2 = nullptr; |
| 32 |
if (!TEST_IS_CONSTANT_EVALUATED) |
| 33 |
assert(A::count == 0); |
| 34 |
assert(s2.get() == 0); |
| 35 |
} |
| 36 |
if (!TEST_IS_CONSTANT_EVALUATED) |
| 37 |
assert(A::count == 0); |
| 38 |
} |
| 39 |
|
| 40 |
TEST_CONSTEXPR_CXX23 bool test() { |
| 41 |
test_basic</*IsArray*/ false>(); |
| 42 |
test_basic<true>(); |
| 43 |
|
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
int main(int, char**) { |
| 48 |
test(); |
| 49 |
#if TEST_STD_VER >= 23 |
| 50 |
static_assert(test()); |
| 51 |
#endif |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |