Skip to content

Commit dd7b119

Browse files
committed
add tests for expected<void>
1 parent 4471615 commit dd7b119

File tree

8 files changed

+50
-0
lines changed

8 files changed

+50
-0
lines changed

libcxx/test/std/utilities/expected/expected.void/ctor/ctor.convert.copy.pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <utility>
3434

3535
#include "test_macros.h"
36+
#include "../../types.h"
3637

3738
// Test Constraints:
3839
template <class T1, class Err1, class T2, class Err2>
@@ -97,6 +98,14 @@ constexpr bool test() {
9798
assert(e1.error() == 5);
9899
}
99100

101+
// convert TailClobberer
102+
{
103+
const std::expected<void, TailClobbererNonTrivialMove<1>> e1;
104+
std::expected<void, TailClobberer<1>> e2 = e1;
105+
assert(!e2.has_value());
106+
assert(!e1.has_value());
107+
}
108+
100109
return true;
101110
}
102111

libcxx/test/std/utilities/expected/expected.void/ctor/ctor.convert.move.pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "MoveOnly.h"
3636
#include "test_macros.h"
37+
#include "../../types.h"
3738

3839
// Test Constraints:
3940
template <class T1, class Err1, class T2, class Err2>
@@ -98,6 +99,14 @@ constexpr bool test() {
9899
assert(e1.error().get() == 0);
99100
}
100101

102+
// convert TailClobberer
103+
{
104+
std::expected<void, TailClobbererNonTrivialMove<1>> e1;
105+
std::expected<void, TailClobberer<1>> e2 = std::move(e1);
106+
assert(!e2.has_value());
107+
assert(!e1.has_value());
108+
}
109+
101110
return true;
102111
}
103112

libcxx/test/std/utilities/expected/expected.void/ctor/ctor.copy.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ constexpr bool test() {
6262
assert(!e2.has_value());
6363
assert(e2.error() == 5);
6464
}
65+
66+
// copy TailClobberer as error
67+
{
68+
const std::expected<void, TailClobberer<1>> e1(std::unexpect);
69+
auto e2 = e1;
70+
assert(!e2.has_value());
71+
}
72+
6573
return true;
6674
}
6775

libcxx/test/std/utilities/expected/expected.void/ctor/ctor.move.pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ constexpr bool test() {
7676
assert(e2.error() == 5);
7777
assert(!e1.has_value());
7878
}
79+
80+
// move TailClobbererNonTrivialMove as error
81+
{
82+
std::expected<void, TailClobbererNonTrivialMove<1>> e1(std::unexpect);
83+
auto e2 = std::move(e1);
84+
assert(!e2.has_value());
85+
assert(!e1.has_value());
86+
}
87+
7988
return true;
8089
}
8190

libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "MoveOnly.h"
2828
#include "test_macros.h"
29+
#include "../../types.h"
2930

3031
// Test Constraints:
3132
static_assert(std::is_constructible_v<std::expected<void, int>, std::unexpect_t>);
@@ -80,10 +81,13 @@ constexpr bool test() {
8081
testInt<int>();
8182
testInt<CopyOnly>();
8283
testInt<MoveOnly>();
84+
testInt<TailClobberer<1>>();
8385
testLValue<int>();
8486
testLValue<CopyOnly>();
87+
testLValue<TailClobberer<1>>();
8588
testRValue<int>();
8689
testRValue<MoveOnly>();
90+
testRValue<TailClobberer<1>>();
8791

8892
// no arg
8993
{

libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect_init_list.pass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "MoveOnly.h"
3030
#include "test_macros.h"
31+
#include "../../types.h"
3132

3233
// Test Constraints:
3334
static_assert(
@@ -89,6 +90,12 @@ constexpr bool test() {
8990
assert(m.get() == 0);
9091
}
9192

93+
// TailClobberer
94+
{
95+
std::expected<void, TailClobberer<1>> e(std::unexpect, {1, 2, 3});
96+
assert(!e.has_value());
97+
}
98+
9299
return true;
93100
}
94101

libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpected.copy.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "MoveOnly.h"
2929
#include "test_macros.h"
30+
#include "../../types.h"
3031

3132
// Test Constraints
3233
static_assert(std::is_constructible_v<std::expected<void, int>, const std::unexpected<int>&>);
@@ -60,6 +61,7 @@ constexpr void testUnexpected() {
6061
constexpr bool test() {
6162
testUnexpected<int>();
6263
testUnexpected<MyInt>();
64+
testUnexpected<TailClobberer<1>>();
6365
return true;
6466
}
6567

libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpected.move.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "MoveOnly.h"
2929
#include "test_macros.h"
30+
#include "../../types.h"
3031

3132
// Test Constraints
3233
static_assert(std::is_constructible_v<std::expected<void, int>, std::unexpected<int>>);
@@ -69,6 +70,7 @@ constexpr bool test() {
6970
testInt<int>();
7071
testInt<MyInt>();
7172
testInt<MoveOnly>();
73+
testInt<TailClobberer<1>>();
7274
testMoveOnly();
7375
return true;
7476
}

0 commit comments

Comments
 (0)