brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · f2e3f6b Raw
54 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <memory>10 11// unique_ptr12 13// Test unique_ptr move assignment14 15#include <memory>16#include <cassert>17 18#include "test_macros.h"19#include "unique_ptr_test_helper.h"20 21// test assignment from null22template <bool IsArray>23TEST_CONSTEXPR_CXX23 void test_basic() {24  typedef typename std::conditional<IsArray, A[], A>::type VT;25  const int expect_alive = IsArray ? 5 : 1;26  {27    std::unique_ptr<VT> s2(newValue<VT>(expect_alive));28    if (!TEST_IS_CONSTANT_EVALUATED)29      assert(A::count == expect_alive);30    s2 = NULL;31    if (!TEST_IS_CONSTANT_EVALUATED)32      assert(A::count == 0);33    assert(s2.get() == 0);34  }35  if (!TEST_IS_CONSTANT_EVALUATED)36    assert(A::count == 0);37}38 39TEST_CONSTEXPR_CXX23 bool test() {40  test_basic</*IsArray*/ false>();41  test_basic<true>();42 43  return true;44}45 46int main(int, char**) {47  test();48#if TEST_STD_VER >= 2349  static_assert(test());50#endif51 52  return 0;53}54