Skip to content

Commit 04066ce

Browse files
committed
U.pass
1 parent ade2260 commit 04066ce

File tree

1 file changed

+95
-56
lines changed
  • libcxx/test/std/utilities/optional/optional.object/optional.object.ctor

1 file changed

+95
-56
lines changed

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

Lines changed: 95 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -44,80 +44,47 @@ struct ImplicitAny {
4444
template <class To, class From>
4545
constexpr bool implicit_conversion(optional<To>&& opt, const From& v) {
4646
using O = optional<To>;
47-
static_assert(test_convertible<O, From>(), "");
48-
static_assert(!test_convertible<O, void*>(), "");
49-
static_assert(!test_convertible<O, From, int>(), "");
50-
return opt && *opt == static_cast<To>(v);
47+
assert((test_convertible<O, From>()));
48+
assert(!(test_convertible<O, void*>()));
49+
assert(!(test_convertible<O, From, int>()));
50+
assert(opt);
51+
assert(*opt == static_cast<To>(v));
52+
53+
return true;
5154
}
5255

5356
template <class To, class Input, class Expect>
5457
constexpr bool explicit_conversion(Input&& in, const Expect& v) {
5558
using O = optional<To>;
56-
static_assert(std::is_constructible<O, Input>::value, "");
57-
static_assert(!std::is_convertible<Input, O>::value, "");
58-
static_assert(!std::is_constructible<O, void*>::value, "");
59-
static_assert(!std::is_constructible<O, Input, int>::value, "");
59+
assert((std::is_constructible<O, Input>::value));
60+
assert(!(std::is_convertible<Input, O>::value));
61+
assert(!(std::is_constructible<O, void*>::value));
62+
assert(!(std::is_constructible<O, Input, int>::value));
63+
6064
optional<To> opt(std::forward<Input>(in));
6165
optional<To> opt2{std::forward<Input>(in)};
62-
return opt && *opt == static_cast<To>(v) && (opt2 && *opt2 == static_cast<To>(v));
66+
assert(opt);
67+
assert(opt2);
68+
assert(*opt == static_cast<To>(v));
69+
assert(*opt2 == static_cast<To>(v));
70+
71+
return true;
6372
}
6473

6574
void test_implicit() {
66-
{
67-
static_assert(implicit_conversion<long long>(42, 42), "");
68-
}
69-
{
70-
static_assert(implicit_conversion<long double>(3.14, 3.14), "");
71-
}
72-
{
73-
int x = 42;
74-
optional<void* const> o(&x);
75-
assert(*o == &x);
76-
}
77-
{
78-
using T = TrivialTestTypes::TestType;
79-
static_assert(implicit_conversion<T>(42, 42), "");
80-
}
81-
{
82-
using T = TestTypes::TestType;
83-
assert(implicit_conversion<T>(3, T(3)));
84-
}
8575
{
8676
using T = TestTypes::TestType;
8777
optional<T> opt({3});
8878
assert(opt && *opt == static_cast<T>(3));
8979
}
80+
9081
{
91-
using O = optional<ImplicitAny>;
92-
static_assert(!test_convertible<O, std::in_place_t>(), "");
93-
static_assert(!test_convertible<O, std::in_place_t&>(), "");
94-
static_assert(!test_convertible<O, const std::in_place_t&>(), "");
95-
static_assert(!test_convertible<O, std::in_place_t&&>(), "");
96-
static_assert(!test_convertible<O, const std::in_place_t&&>(), "");
97-
}
98-
#ifndef TEST_HAS_NO_EXCEPTIONS
99-
{
100-
try {
101-
using T = ImplicitThrow;
102-
optional<T> t = 42;
103-
assert(false);
104-
((void)t);
105-
} catch (int) {
106-
}
82+
using T = TestTypes::TestType;
83+
assert((implicit_conversion<T>(3, T(3))));
10784
}
108-
#endif
10985
}
11086

11187
void test_explicit() {
112-
{
113-
using T = ExplicitTrivialTestTypes::TestType;
114-
static_assert(explicit_conversion<T>(42, 42), "");
115-
}
116-
{
117-
using T = ExplicitConstexprTestTypes::TestType;
118-
static_assert(explicit_conversion<T>(42, 42), "");
119-
static_assert(!std::is_convertible<int, T>::value, "");
120-
}
12188
{
12289
using T = ExplicitTestTypes::TestType;
12390
T::reset();
@@ -136,7 +103,20 @@ void test_explicit() {
136103
}
137104
assert(T::alive == 0);
138105
}
106+
}
107+
108+
TEST_CONSTEXPR_CXX26 void test_throwing() {
139109
#ifndef TEST_HAS_NO_EXCEPTIONS
110+
{
111+
try {
112+
using T = ImplicitThrow;
113+
optional<T> t = 42;
114+
assert(false);
115+
((void)t);
116+
} catch (int) {
117+
}
118+
}
119+
140120
{
141121
try {
142122
using T = ExplicitThrow;
@@ -148,9 +128,68 @@ void test_explicit() {
148128
#endif
149129
}
150130

131+
constexpr bool test() {
132+
{
133+
assert((implicit_conversion<long long>(42, 42)));
134+
}
135+
136+
{
137+
assert((implicit_conversion<long double>(3.14, 3.14)));
138+
}
139+
140+
{
141+
int x = 42;
142+
optional<void* const> o(&x);
143+
assert(*o == &x);
144+
}
145+
146+
{
147+
using T = TrivialTestTypes::TestType;
148+
assert((implicit_conversion<T>(42, 42)));
149+
}
150+
151+
{
152+
using O = optional<ImplicitAny>;
153+
assert(!(test_convertible<O, std::in_place_t>()));
154+
assert(!(test_convertible<O, std::in_place_t&>()));
155+
assert(!(test_convertible<O, const std::in_place_t&>()));
156+
assert(!(test_convertible<O, std::in_place_t&&>()));
157+
assert(!(test_convertible<O, const std::in_place_t&&>()));
158+
}
159+
160+
{
161+
using T = ExplicitTrivialTestTypes::TestType;
162+
assert((explicit_conversion<T>(42, 42)));
163+
}
164+
165+
{
166+
using T = ExplicitConstexprTestTypes::TestType;
167+
assert(explicit_conversion<T>(42, 42));
168+
assert(!(std::is_convertible<int, T>::value));
169+
}
170+
171+
#if TEST_STD_VER >= 26 && 0
172+
test_throwing();
173+
#endif
174+
175+
return true;
176+
}
177+
151178
int main(int, char**) {
152-
test_implicit();
153-
test_explicit();
179+
test();
180+
static_assert(test());
181+
182+
{
183+
test_implicit();
184+
}
185+
186+
{
187+
test_explicit();
188+
}
189+
190+
{
191+
test_throwing();
192+
}
154193

155194
return 0;
156195
}

0 commit comments

Comments
 (0)