summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/unique_ptr/creation/constexpr.cc
blob: 90d11198578935b49aedfd57b0afe361a005f8f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// { dg-options "-std=gnu++23" }
// { dg-do compile { target c++23 } }

#include <memory>
#include <testsuite_hooks.h>

constexpr bool
test_creation_single()
{
  std::unique_ptr<int> p = std::make_unique<int>(1);
  VERIFY( *p == 1 );
  p = std::make_unique_for_overwrite<int>();
  *p = 2;
  VERIFY( *p == 2 );

  return true;
}
static_assert( test_creation_single() );

constexpr bool
test_creation_array()
{
  std::unique_ptr<int[]> a = std::make_unique<int[]>(2);
  VERIFY( a[0] == 0 );
  VERIFY( a[1] == 0 );
  a = std::make_unique_for_overwrite<int[]>(2);
  a[0] = 1;
  a[1] = 2;
  VERIFY( a[0] == 1 );
  VERIFY( a[1] == 2 );

  return true;
}
static_assert( test_creation_array() );