Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.nonmodifying / alg.any_of / pstl.exception_handling.pass.cpp
blob167c4ac4df95e3f134181ed206ca2a9e185c8d9a
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::any_of(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[] = {1, 2};
27 (void)std::any_of(policy, std::begin(a), std::end(a), [](int i) -> bool { throw i; });
28 });
29 EXPECT_STD_TERMINATE([&] {
30 try {
31 int a[] = {1, 2};
32 (void)std::any_of(
33 policy,
34 util::throw_on_move_iterator(std::begin(a), 1),
35 util::throw_on_move_iterator(std::end(a), 1),
36 [](int) { return true; });
37 } catch (const util::iterator_error&) {
38 assert(false);
40 std::terminate(); // make the test pass in case the algorithm didn't move the iterator
41 });
42 });