brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · cc68297 Raw
76 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 constexpr explicit operator bool() const noexcept; // constexpr since C++2314 15#include <memory>16#include <cassert>17 18#include "test_macros.h"19#include "unique_ptr_test_helper.h"20 21template <class UPtr>22TEST_CONSTEXPR_CXX23 void doTest(UPtr& p, bool ExpectTrue) {23  if (p)24    assert(ExpectTrue);25  else26    assert(!ExpectTrue);27 28  if (!p)29    assert(!ExpectTrue);30  else31    assert(ExpectTrue);32}33 34template <bool IsArray>35TEST_CONSTEXPR_CXX23 void test_basic() {36  typedef typename std::conditional<IsArray, int[], int>::type VT;37  typedef std::unique_ptr<VT> U;38  {39    static_assert((std::is_constructible<bool, U>::value), "");40    static_assert((std::is_constructible<bool, U const&>::value), "");41  }42#if TEST_STD_VER >= 1143  {44    static_assert(!std::is_convertible<U, bool>::value, "");45    static_assert(!std::is_convertible<U const&, bool>::value, "");46  }47#endif48  {49    U p(newValue<VT>(1));50    U const& cp = p;51    doTest(p, true);52    doTest(cp, true);53  }54  {55    U p;56    const U& cp = p;57    doTest(p, false);58    doTest(cp, false);59  }60}61 62TEST_CONSTEXPR_CXX23 bool test() {63  test_basic</*IsArray*/ false>();64  test_basic<true>();65 66  return true;67}68 69int main(int, char**) {70  test();71#if TEST_STD_VER >= 2372  static_assert(test());73#endif74 75  return 0;76}