brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 54aec49 Raw
61 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// The deleter is not called if get() == 014 15#include <memory>16#include <cassert>17 18#include "test_macros.h"19 20class Deleter {21  int state_;22 23  Deleter(Deleter&);24  Deleter& operator=(Deleter&);25 26public:27  TEST_CONSTEXPR_CXX23 Deleter() : state_(0) {}28 29  TEST_CONSTEXPR_CXX23 int state() const { return state_; }30 31  TEST_CONSTEXPR_CXX23 void operator()(void*) { ++state_; }32};33 34template <class T>35TEST_CONSTEXPR_CXX23 void test_basic() {36  Deleter d;37  assert(d.state() == 0);38  {39    std::unique_ptr<T, Deleter&> p(nullptr, d);40    assert(p.get() == nullptr);41    assert(&p.get_deleter() == &d);42  }43  assert(d.state() == 0);44}45 46TEST_CONSTEXPR_CXX23 bool test() {47  test_basic<int>();48  test_basic<int[]>();49 50  return true;51}52 53int main(int, char**) {54  test();55#if TEST_STD_VER >= 2356  static_assert(test());57#endif58 59  return 0;60}61