Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.transform / pstl.exception_handling.pass.cpp
blob6c7149f4048ade84850061aeb5d9c2a35e11a759
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
10 // UNSUPPORTED: no-exceptions
11 // REQUIRES: has-unix-headers
13 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
15 // check that std::transform(ExecutionPolicy) terminates on user-thrown exceptions
17 #include <algorithm>
19 #include "check_assertion.h"
20 #include "test_execution_policies.h"
21 #include "test_iterators.h"
23 int main(int, char**) {
24 test_execution_policies([&](auto&& policy) {
25 EXPECT_STD_TERMINATE([&] {
26 int a[2]{};
27 int b[2]{};
28 int c[2]{};
29 (void)std::transform(
30 policy, std::begin(a), std::end(a), std::begin(b), std::begin(c), [](auto v, auto) -> decltype(v) {
31 throw int{};
32 });
33 });
34 EXPECT_STD_TERMINATE([&] {
35 try {
36 int a[] = {1, 2};
37 (void)std::transform(
38 policy,
39 util::throw_on_move_iterator(std::begin(a), 1),
40 util::throw_on_move_iterator(std::end(a), 1),
41 util::throw_on_move_iterator(std::begin(a), 1),
42 [](int i) { return i; });
43 } catch (const util::iterator_error&) {
44 assert(false);
46 std::terminate(); // make the test pass in case the algorithm didn't move the iterator
47 });
49 EXPECT_STD_TERMINATE([&] {
50 int a[2]{};
51 int b[2]{};
52 (void)std::transform(policy, std::begin(a), std::end(a), std::begin(b), [](auto v) -> decltype(v) {
53 throw int{};
54 });
55 });
56 EXPECT_STD_TERMINATE([&] {
57 try {
58 int a[] = {1, 2};
59 (void)std::transform(
60 policy,
61 util::throw_on_move_iterator(std::begin(a), 1),
62 util::throw_on_move_iterator(std::end(a), 1),
63 util::throw_on_move_iterator(std::begin(a), 1),
64 util::throw_on_move_iterator(std::begin(a), 1),
65 std::plus{});
66 } catch (const util::iterator_error&) {
67 assert(false);
69 std::terminate(); // make the test pass in case the algorithm didn't move the iterator
70 });
71 });