Skip to content

Commit 8f3242a

Browse files
committed
WIP: Improve testing of exception handling.
Move elision was happening and could render the tests useless. Also take the occasion in this patch to handle all algorithms. Can easily(?) be landed before the rest.
1 parent d5006e5 commit 8f3242a

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

libcxx/test/std/algorithms/numeric.ops/reduce/pstl.exception_handling.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ int main(int, char**) {
3838
int a[2]{};
3939
(void)std::reduce(policy, std::begin(a), std::end(a), 1, [](int, int) -> int { throw 1; });
4040
});
41+
4142
EXPECT_STD_TERMINATE([&] {
4243
try {
4344
int a[] = {1, 2};

libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.exception_handling.pass.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,43 @@ int main(int, char**) {
2626
EXPECT_STD_TERMINATE([&] {
2727
try {
2828
int a[] = {1, 2};
29-
(void)std::transform_reduce(
30-
policy,
31-
util::throw_on_move_iterator(std::begin(a), 1),
32-
util::throw_on_move_iterator(std::end(a), 1),
33-
util::throw_on_move_iterator(std::begin(a), 1),
34-
1);
29+
util::throw_on_move_iterator first1(std::begin(a), 1);
30+
util::throw_on_move_iterator last1(std::end(a), 1);
31+
util::throw_on_move_iterator first2(std::begin(a), 1);
32+
(void)std::transform_reduce(policy, std::move(first1), std::move(last1), std::move(first2), 1);
3533
} catch (const util::iterator_error&) {
3634
assert(false);
3735
}
3836
std::terminate(); // make the test pass in case the algorithm didn't move the iterator
3937
});
4038

4139
EXPECT_STD_TERMINATE([&] {
42-
int a[2]{};
40+
int a[] = {1, 2};
4341
(void)std::transform_reduce(
4442
policy, std::begin(a), std::end(a), 1, [](int, int) -> int { throw 1; }, [](int) -> int { return 0; });
4543
});
44+
45+
EXPECT_STD_TERMINATE([&] {
46+
try {
47+
int a[] = {1, 2};
48+
util::throw_on_move_iterator first1(std::begin(a), 1);
49+
util::throw_on_move_iterator last1(std::end(a), 1);
50+
(void)std::transform_reduce(policy, std::move(first1), std::move(last1), 1, std::plus{}, [](int) -> int {
51+
return 0;
52+
});
53+
} catch (const util::iterator_error&) {
54+
assert(false);
55+
}
56+
std::terminate(); // make the test pass in case the algorithm didn't move the iterator
57+
});
58+
4659
EXPECT_STD_TERMINATE([&] {
4760
try {
4861
int a[] = {1, 2};
49-
(void)std::transform_reduce(
50-
policy,
51-
util::throw_on_move_iterator(std::begin(a), 1),
52-
util::throw_on_move_iterator(std::end(a), 1),
53-
1,
54-
std::plus{},
55-
[](int) -> int { return 0; });
62+
util::throw_on_move_iterator first1(std::begin(a), 1);
63+
util::throw_on_move_iterator last1(std::end(a), 1);
64+
util::throw_on_move_iterator first2(std::begin(a), 1);
65+
(void)std::transform_reduce(policy, std::move(first1), std::move(last1), std::move(first2), 1);
5666
} catch (const util::iterator_error&) {
5767
assert(false);
5868
}

0 commit comments

Comments
 (0)