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 // <ranges>
10
11 // Call begin() on drop_while_view with empty predicate
12
13 // REQUIRES: has-unix-headers
14 // UNSUPPORTED: c++03, c++11, c++14, c++17
15 // UNSUPPORTED: no-exceptions
16 // REQUIRES: libcpp-hardening-mode={{extensive|debug}}
17 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
18
19 #include <ranges>
20
21 #include "check_assertion.h"
22
23 struct Exception {};
24 struct ThrowOnCopyPred {
25 ThrowOnCopyPred() = default;
ThrowOnCopyPredThrowOnCopyPred26 ThrowOnCopyPred(const ThrowOnCopyPred&) { throw Exception{}; }
27 ThrowOnCopyPred& operator=(const ThrowOnCopyPred&) = delete;
28
29 ThrowOnCopyPred(ThrowOnCopyPred&&) = default;
30 ThrowOnCopyPred& operator=(ThrowOnCopyPred&&) = default;
31
operator ()ThrowOnCopyPred32 bool operator()(int) const { return false; }
33 };
34
main(int,char **)35 int main(int, char**) {
36 int input[] = {1, 2, 3};
37 auto v1 = std::views::drop_while(input, ThrowOnCopyPred{});
38 auto v2 = std::views::drop_while(input, ThrowOnCopyPred{});
39 try {
40 v1 = v2;
41 } catch (...) {
42 }
43 TEST_LIBCPP_ASSERT_FAILURE(
44 v1.begin(),
45 "drop_while_view needs to have a non-empty predicate before calling begin() -- did a "
46 "previous assignment to this drop_while_view fail?");
47
48 return 0;
49 }
50