Debian Codegraph @

libstdc++-v3/testsuite/20_util/unique_ptr/creation/constexpr.cc

raw
1 // { dg-do compile { target c++23 } }
2 // { dg-require-effective-target hosted }
3
4 #include <memory>
5 #include <testsuite_hooks.h>
6
7 constexpr bool
8 test_creation_single()
9 {
10 std::unique_ptr<int> p = std::make_unique<int>(1);
11 VERIFY( *p == 1 );
12 p = std::make_unique_for_overwrite<int>();
13 *p = 2;
14 VERIFY( *p == 2 );
15
16 return true;
17 }
18 static_assert( test_creation_single() );
19
20 constexpr bool
21 test_creation_array()
22 {
23 std::unique_ptr<int[]> a = std::make_unique<int[]>(2);
24 VERIFY( a[0] == 0 );
25 VERIFY( a[1] == 0 );
26 a = std::make_unique_for_overwrite<int[]>(2);
27 a[0] = 1;
28 a[1] = 2;
29 VERIFY( a[0] == 1 );
30 VERIFY( a[1] == 2 );
31
32 return true;
33 }
34 static_assert( test_creation_array() );