Skip to content

Commit 3d253e2

Browse files
committed
rvalue_T
1 parent db19ac0 commit 3d253e2

File tree

1 file changed

+63
-53
lines changed
  • libcxx/test/std/utilities/optional/optional.object/optional.object.ctor

1 file changed

+63
-53
lines changed

libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8-
//
8+
99
// REQUIRED: std-at-least-c++17
1010

1111
// <optional>
@@ -27,32 +27,27 @@ class Z {
2727
Z(Z&&) { TEST_THROW(6); }
2828
};
2929

30-
int main(int, char**) {
30+
template <typename T, typename U>
31+
constexpr void test_rvalueT(U arg) {
3132
{
32-
typedef int T;
33-
constexpr optional<T> opt(T(5));
34-
static_assert(static_cast<bool>(opt) == true, "");
35-
static_assert(*opt == 5, "");
36-
37-
struct test_constexpr_ctor : public optional<T> {
38-
constexpr test_constexpr_ctor(T&&) {}
39-
};
40-
}
41-
{
42-
typedef double T;
43-
constexpr optional<T> opt(T(3));
44-
static_assert(static_cast<bool>(opt) == true, "");
45-
static_assert(*opt == 3, "");
46-
47-
struct test_constexpr_ctor : public optional<T> {
48-
constexpr test_constexpr_ctor(T&&) {}
49-
};
33+
const optional<T> opt(arg);
34+
assert(bool(opt));
35+
assert(*opt == T(arg));
5036
}
37+
5138
{
52-
const int x = 42;
53-
optional<const int> o(std::move(x));
54-
assert(*o == 42);
39+
T t(arg);
40+
optional<T> opt(std::move(t));
41+
assert(*opt == T(arg));
5542
}
43+
44+
struct test_constexpr_ctor : public optional<T> {
45+
constexpr test_constexpr_ctor(T&&) {}
46+
constexpr test_constexpr_ctor(const T&) {}
47+
};
48+
}
49+
50+
void test_rt() {
5651
{
5752
typedef TestTypes::TestType T;
5853
T::reset();
@@ -83,37 +78,9 @@ int main(int, char**) {
8378
assert(static_cast<bool>(opt) == true);
8479
assert(opt.value().value == 3);
8580
}
86-
{
87-
typedef ConstexprTestTypes::TestType T;
88-
constexpr optional<T> opt = {T(3)};
89-
static_assert(static_cast<bool>(opt) == true, "");
90-
static_assert(opt.value().value == 3, "");
91-
92-
struct test_constexpr_ctor : public optional<T> {
93-
constexpr test_constexpr_ctor(const T&) {}
94-
};
95-
}
96-
{
97-
typedef ConstexprTestTypes::TestType T;
98-
constexpr optional<T> opt = {3};
99-
static_assert(static_cast<bool>(opt) == true, "");
100-
static_assert(opt.value().value == 3, "");
101-
102-
struct test_constexpr_ctor : public optional<T> {
103-
constexpr test_constexpr_ctor(const T&) {}
104-
};
105-
}
106-
{
107-
typedef ExplicitConstexprTestTypes::TestType T;
108-
static_assert(!std::is_convertible<T&&, optional<T>>::value, "");
109-
constexpr optional<T> opt(T{3});
110-
static_assert(static_cast<bool>(opt) == true, "");
111-
static_assert(opt.value().value == 3, "");
81+
}
11282

113-
struct test_constexpr_ctor : public optional<T> {
114-
constexpr test_constexpr_ctor(T&&) {}
115-
};
116-
}
83+
TEST_CONSTEXPR_CXX26 void test_throwing() {
11784
#ifndef TEST_HAS_NO_EXCEPTIONS
11885
{
11986
try {
@@ -125,6 +92,49 @@ int main(int, char**) {
12592
}
12693
}
12794
#endif
95+
}
96+
97+
constexpr bool test() {
98+
test_rvalueT<int>(5);
99+
test_rvalueT<double>(3.0);
100+
test_rvalueT<const int>(42);
101+
102+
{
103+
using T = ConstexprTestTypes::TestType;
104+
test_rvalueT<T>(T(3));
105+
}
106+
107+
{
108+
using T = ConstexprTestTypes::TestType;
109+
test_rvalueT<T>(3);
110+
}
111+
112+
{
113+
using T = ExplicitConstexprTestTypes::TestType;
114+
static_assert(!std::is_convertible<T&&, optional<T>>::value);
115+
test_rvalueT<T>(T(3));
116+
}
117+
#if TEST_STD_VER >= 26 && 0
118+
{
119+
test_throwing();
120+
}
121+
122+
#endif
123+
124+
return true;
125+
}
126+
127+
int main(int, char**) {
128+
test();
129+
static_assert(test());
130+
131+
{
132+
test_rt();
133+
}
134+
135+
{
136+
test_throwing();
137+
}
128138

129139
return 0;
130140
}

0 commit comments

Comments
 (0)