Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.fill / pstl.exception_handling.pass.cpp
blobf7279655cb129f964477f3a7925369e6e0360895
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::fill(ExecutionPolicy) and std::fill_n(ExecutionPolicy) terminate on user-thrown exceptions
17 #include <algorithm>
19 #include "check_assertion.h"
20 #include "test_execution_policies.h"
21 #include "test_iterators.h"
23 #ifndef TEST_HAS_NO_EXCEPTIONS
24 struct ThrowOnCopy {
25 ThrowOnCopy& operator=(const ThrowOnCopy&) { throw int{}; }
27 #endif
29 int main(int, char**) {
30 ThrowOnCopy a[2]{};
31 int b[2]{};
33 test_execution_policies([&](auto&& policy) {
34 // std::fill
35 EXPECT_STD_TERMINATE([&] { (void)std::fill(policy, std::begin(a), std::end(a), ThrowOnCopy{}); });
36 EXPECT_STD_TERMINATE([&] {
37 try {
38 (void)std::fill(
39 policy, util::throw_on_move_iterator(std::begin(b), 1), util::throw_on_move_iterator(std::end(b), 1), 0);
40 } catch (const util::iterator_error&) {
41 assert(false);
43 std::terminate(); // make the test pass in case the algorithm didn't move the iterator
44 });
46 // std::fill_n
47 EXPECT_STD_TERMINATE([&] { (void)std::fill_n(policy, std::begin(a), std::size(a), ThrowOnCopy{}); });
48 EXPECT_STD_TERMINATE([&] {
49 try {
50 (void)std::fill_n(policy, util::throw_on_move_iterator(std::begin(b), 1), std::size(b), 0);
51 } catch (const util::iterator_error&) {
52 assert(false);
54 std::terminate(); // make the test pass in case the algorithm didn't move the iterator
55 });
56 });