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-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <memory>
10
11 // unique_ptr
12
13 // test constexpr explicit operator bool() const noexcept; // constexpr since C++23
14
15 #include <memory>
16 #include <cassert>
17
18 #include "test_macros.h"
19 #include "unique_ptr_test_helper.h"
20
21 template <class UPtr>
doTest(UPtr & p,bool ExpectTrue)22 TEST_CONSTEXPR_CXX23 void doTest(UPtr& p, bool ExpectTrue) {
23 if (p)
24 assert(ExpectTrue);
25 else
26 assert(!ExpectTrue);
27
28 if (!p)
29 assert(!ExpectTrue);
30 else
31 assert(ExpectTrue);
32 }
33
34 template <bool IsArray>
test_basic()35 TEST_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 >= 11
43 {
44 static_assert(!std::is_convertible<U, bool>::value, "");
45 static_assert(!std::is_convertible<U const&, bool>::value, "");
46 }
47 #endif
48 {
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
test()62 TEST_CONSTEXPR_CXX23 bool test() {
63 test_basic</*IsArray*/ false>();
64 test_basic<true>();
65
66 return true;
67 }
68
main(int,char **)69 int main(int, char**) {
70 test();
71 #if TEST_STD_VER >= 23
72 static_assert(test());
73 #endif
74
75 return 0;
76 }