1 //===----------------------------------------------------------------------===//
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
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
19 #include "check_assertion.h"
20 #include "test_execution_policies.h"
21 #include "test_iterators.h"
23 #ifndef TEST_HAS_NO_EXCEPTIONS
25 ThrowOnCopy
& operator=(const ThrowOnCopy
&) { throw int{}; }
29 int main(int, char**) {
33 test_execution_policies([&](auto&& policy
) {
35 EXPECT_STD_TERMINATE([&] { (void)std::fill(policy
, std::begin(a
), std::end(a
), ThrowOnCopy
{}); });
36 EXPECT_STD_TERMINATE([&] {
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
&) {
43 std::terminate(); // make the test pass in case the algorithm didn't move the iterator
47 EXPECT_STD_TERMINATE([&] { (void)std::fill_n(policy
, std::begin(a
), std::size(a
), ThrowOnCopy
{}); });
48 EXPECT_STD_TERMINATE([&] {
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
&) {
54 std::terminate(); // make the test pass in case the algorithm didn't move the iterator