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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14 |
10 | // UNSUPPORTED: no-exceptions |
11 | // `check_assertion.h` requires Unix headers and regex support. |
12 | // UNSUPPORTED: !has-unix-headers, no-localization |
13 | |
14 | // UNSUPPORTED: libcpp-has-no-incomplete-pstl |
15 | |
16 | // check that std::transform(ExecutionPolicy) terminates on user-thrown exceptions |
17 | |
18 | #include <algorithm> |
19 | |
20 | #include "check_assertion.h" |
21 | #include "test_execution_policies.h" |
22 | #include "test_iterators.h" |
23 | |
24 | int main(int, char**) { |
25 | test_execution_policies([&](auto&& policy) { |
26 | EXPECT_STD_TERMINATE([&] { |
27 | int a[2]{}; |
28 | int b[2]{}; |
29 | int c[2]{}; |
30 | (void)std::transform( |
31 | policy, std::begin(arr&: a), std::end(arr&: a), std::begin(arr&: b), std::begin(arr&: c), [](auto v, auto) -> decltype(v) { |
32 | throw int{}; |
33 | }); |
34 | }); |
35 | EXPECT_STD_TERMINATE([&] { |
36 | try { |
37 | int a[] = {1, 2}; |
38 | (void)std::transform( |
39 | policy, |
40 | util::throw_on_move_iterator(std::begin(a), 1), |
41 | util::throw_on_move_iterator(std::end(a), 1), |
42 | util::throw_on_move_iterator(std::begin(a), 1), |
43 | [](int i) { return i; }); |
44 | } catch (const util::iterator_error&) { |
45 | assert(false); |
46 | } |
47 | std::terminate(); // make the test pass in case the algorithm didn't move the iterator |
48 | }); |
49 | |
50 | EXPECT_STD_TERMINATE([&] { |
51 | int a[2]{}; |
52 | int b[2]{}; |
53 | (void)std::transform(policy, std::begin(arr&: a), std::end(arr&: a), std::begin(arr&: b), [](auto v) -> decltype(v) { |
54 | throw int{}; |
55 | }); |
56 | }); |
57 | EXPECT_STD_TERMINATE([&] { |
58 | try { |
59 | int a[] = {1, 2}; |
60 | (void)std::transform( |
61 | policy, |
62 | util::throw_on_move_iterator(std::begin(a), 1), |
63 | util::throw_on_move_iterator(std::end(a), 1), |
64 | util::throw_on_move_iterator(std::begin(a), 1), |
65 | util::throw_on_move_iterator(std::begin(a), 1), |
66 | std::plus{}); |
67 | } catch (const util::iterator_error&) { |
68 | assert(false); |
69 | } |
70 | std::terminate(); // make the test pass in case the algorithm didn't move the iterator |
71 | }); |
72 | }); |
73 | } |
74 | |