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 reset
14
15#include <memory>
16#include <cassert>
17
18#include "test_macros.h"
19#include "unique_ptr_test_helper.h"
20
21TEST_CONSTEXPR_CXX23 bool test() {
22 {
23 std::unique_ptr<A> p(new A);
24 if (!TEST_IS_CONSTANT_EVALUATED) {
25 assert(A::count == 1);
26 assert(B::count == 0);
27 }
28 A* i = p.get();
29 assert(i != nullptr);
30 p.reset(new B);
31 if (!TEST_IS_CONSTANT_EVALUATED) {
32 assert(A::count == 1);
33 assert(B::count == 1);
34 }
35 }
36 if (!TEST_IS_CONSTANT_EVALUATED) {
37 assert(A::count == 0);
38 assert(B::count == 0);
39 }
40 {
41 std::unique_ptr<A> p(new B);
42 if (!TEST_IS_CONSTANT_EVALUATED) {
43 assert(A::count == 1);
44 assert(B::count == 1);
45 }
46 A* i = p.get();
47 assert(i != nullptr);
48 p.reset(new B);
49 if (!TEST_IS_CONSTANT_EVALUATED) {
50 assert(A::count == 1);
51 assert(B::count == 1);
52 }
53 }
54 if (!TEST_IS_CONSTANT_EVALUATED) {
55 assert(A::count == 0);
56 assert(B::count == 0);
57 }
58
59 return true;
60}
61
62int main(int, char**) {
63 test();
64#if TEST_STD_VER >= 23
65 static_assert(test());
66#endif
67
68 return 0;
69}
70

source code of libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.single.pass.cpp