[CodeGen] Introduce a VirtRegOrUnit class to hold virtual reg or physical reg unit...
[llvm-project.git] / libcxx / test / std / utilities / optional / optional.object / optional.object.ctor / rvalue_T.pass.cpp
blob12425955f5a8683cdff004ee1a810d378ea1d04a
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 // UNSUPPORTED: c++03, c++11, c++14
11 // <optional>
13 // constexpr optional(T&& v);
15 #include <optional>
16 #include <type_traits>
17 #include <cassert>
19 #include "test_macros.h"
20 #include "archetypes.h"
23 using std::optional;
26 class Z
28 public:
29 Z(int) {}
30 Z(Z&&) {TEST_THROW(6);}
34 int main(int, char**)
37 typedef int T;
38 constexpr optional<T> opt(T(5));
39 static_assert(static_cast<bool>(opt) == true, "");
40 static_assert(*opt == 5, "");
42 struct test_constexpr_ctor
43 : public optional<T>
45 constexpr test_constexpr_ctor(T&&) {}
49 typedef double T;
50 constexpr optional<T> opt(T(3));
51 static_assert(static_cast<bool>(opt) == true, "");
52 static_assert(*opt == 3, "");
54 struct test_constexpr_ctor
55 : public optional<T>
57 constexpr test_constexpr_ctor(T&&) {}
61 const int x = 42;
62 optional<const int> o(std::move(x));
63 assert(*o == 42);
66 typedef TestTypes::TestType T;
67 T::reset();
68 optional<T> opt = T{3};
69 assert(T::alive == 1);
70 assert(T::move_constructed == 1);
71 assert(static_cast<bool>(opt) == true);
72 assert(opt.value().value == 3);
75 typedef ExplicitTestTypes::TestType T;
76 static_assert(!std::is_convertible<T&&, optional<T>>::value, "");
77 T::reset();
78 optional<T> opt(T{3});
79 assert(T::alive == 1);
80 assert(T::move_constructed == 1);
81 assert(static_cast<bool>(opt) == true);
82 assert(opt.value().value == 3);
85 typedef TestTypes::TestType T;
86 T::reset();
87 optional<T> opt = {3};
88 assert(T::alive == 1);
89 assert(T::value_constructed == 1);
90 assert(T::copy_constructed == 0);
91 assert(T::move_constructed == 0);
92 assert(static_cast<bool>(opt) == true);
93 assert(opt.value().value == 3);
96 typedef ConstexprTestTypes::TestType T;
97 constexpr optional<T> opt = {T(3)};
98 static_assert(static_cast<bool>(opt) == true, "");
99 static_assert(opt.value().value == 3, "");
101 struct test_constexpr_ctor
102 : public optional<T>
104 constexpr test_constexpr_ctor(const T&) {}
108 typedef ConstexprTestTypes::TestType T;
109 constexpr optional<T> opt = {3};
110 static_assert(static_cast<bool>(opt) == true, "");
111 static_assert(opt.value().value == 3, "");
113 struct test_constexpr_ctor
114 : public optional<T>
116 constexpr test_constexpr_ctor(const T&) {}
120 typedef ExplicitConstexprTestTypes::TestType T;
121 static_assert(!std::is_convertible<T&&, optional<T>>::value, "");
122 constexpr optional<T> opt(T{3});
123 static_assert(static_cast<bool>(opt) == true, "");
124 static_assert(opt.value().value == 3, "");
126 struct test_constexpr_ctor
127 : public optional<T>
129 constexpr test_constexpr_ctor(T&&) {}
133 #ifndef TEST_HAS_NO_EXCEPTIONS
137 Z z(3);
138 optional<Z> opt(std::move(z));
139 assert(false);
141 catch (int i)
143 assert(i == 6);
146 #endif
148 return 0;