Skip to content

Commit bec1572

Browse files
committed
changes requirements test from asserts to verify
1 parent 15b686b commit bec1572

File tree

2 files changed

+203
-107
lines changed

2 files changed

+203
-107
lines changed

libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/fold_left_with_iter/requirements.compile.pass.cpp

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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+
// <algorithm>
10+
11+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
12+
13+
// Checks that `std::ranges::fold_left_with_iter`'s requirements are correct.
14+
15+
#include <algorithm>
16+
#include <concepts>
17+
#include <functional>
18+
#include <iterator>
19+
#include <ranges>
20+
21+
#include "test_range.h"
22+
#include "test_iterators.h"
23+
#include "../requirements.h"
24+
25+
// expected-error@*:* 19 {{no matching function for call to object of type 'const __fold_left_with_iter'}}
26+
27+
void test_iterator() {
28+
// expected-note@*:* 10 {{candidate template ignored: constraints not satisfied}}
29+
// expected-note@*:* 10 {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
30+
31+
std::ranges::fold_left_with_iter(bad_iterator_category(), std::unreachable_sentinel, 0, std::plus());
32+
// expected-note@*:* {{because 'bad_iterator_category' does not satisfy 'input_iterator'}}
33+
// expected-note@*:* {{because 'derived_from<_ITER_CONCEPT<bad_iterator_category>, input_iterator_tag>' evaluated to false}}
34+
// expected-note@*:* {{because 'is_base_of_v<std::input_iterator_tag, void>' evaluated to false}}
35+
36+
{
37+
int* first;
38+
int* last;
39+
std::ranges::fold_left_with_iter(
40+
cpp17_input_iterator<int*>(first), cpp17_input_iterator<int*>(last), 0, std::plus());
41+
// expected-note@*:* {{because 'sentinel_for<cpp17_input_iterator<int *>, cpp17_input_iterator<int *> >' evaluated to false}}
42+
// expected-note@*:* {{because 'cpp17_input_iterator<int *>' does not satisfy 'semiregular'}}
43+
// expected-note@*:* {{'cpp17_input_iterator<int *>' does not satisfy 'default_initializable'}}
44+
// expected-note@*:* {{because 'cpp17_input_iterator<int *>' does not satisfy 'constructible_from'}}
45+
// expected-note@*:* {{because 'is_constructible_v<cpp17_input_iterator<int *> >' evaluated to false}}
46+
47+
std::ranges::fold_left_with_iter(first, last, 0, non_copy_constructible_callable());
48+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<non_copy_constructible_callable, int, int *>' evaluated to false}}
49+
// expected-note@*:* {{because 'non_copy_constructible_callable' does not satisfy 'copy_constructible'}}
50+
// expected-note@*:* {{because 'constructible_from<non_copy_constructible_callable, non_copy_constructible_callable &>' evaluated to false}}
51+
// expected-note@*:* {{because 'is_constructible_v<non_copy_constructible_callable, non_copy_constructible_callable &>' evaluated to false}}
52+
53+
std::ranges::fold_left_with_iter(first, last, 0, not_invocable());
54+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<not_invocable, int, int *>' evaluated to false}}
55+
// expected-note@*:* {{because 'invocable<not_invocable &, int, iter_reference_t<int *> >' evaluated to false}}
56+
// expected-note@*:* {{because 'std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)' would be invalid: no matching function for call to 'invoke'}}
57+
}
58+
{
59+
S* first = nullptr;
60+
S* last = nullptr;
61+
std::ranges::fold_left_with_iter(first, last, S(), non_decayable_result());
62+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<non_decayable_result, S, S *>' evaluated to false}}
63+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<non_decayable_result, S, S *, invoke_result_t<non_decayable_result &, S, iter_reference_t<S *> > >' evaluated to false}}
64+
// expected-note@*:* {{because 'convertible_to<volatile S &, S>' evaluated to false}}
65+
// expected-note@*:* {{because 'is_convertible_v<volatile S &, S>' evaluated to false}}
66+
}
67+
{
68+
copyable_non_movable* first;
69+
copyable_non_movable* last;
70+
std::ranges::fold_left_with_iter(first, last, non_movable(), std::plus());
71+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, non_movable, copyable_non_movable *>' evaluated to false}}
72+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, non_movable, copyable_non_movable *, invoke_result_t<plus<void> &, non_movable, iter_reference_t<copyable_non_movable *> > >' evaluated to false}}
73+
// expected-note@*:* {{because 'non_movable' does not satisfy 'movable'}}
74+
// expected-note@*:* {{because 'non_movable' does not satisfy 'move_constructible'}}
75+
// expected-note@*:* {{because 'constructible_from<non_movable, non_movable>' evaluated to false}}
76+
// expected-note@*:* {{because 'is_constructible_v<non_movable, non_movable>' evaluated to false}}
77+
}
78+
{
79+
copyable_non_movable* first;
80+
copyable_non_movable* last;
81+
std::ranges::fold_left_with_iter(first, last, 0, std::minus());
82+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::minus<void>, int, copyable_non_movable *>' evaluated to false}}
83+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::minus<void>, int, copyable_non_movable *, invoke_result_t<minus<void> &, int, iter_reference_t<copyable_non_movable *> > >' evaluated to false}}
84+
// expected-note@*:* {{because 'copyable_non_movable' does not satisfy 'movable'}}
85+
// expected-note@*:* {{because 'copyable_non_movable' does not satisfy 'move_constructible'}}
86+
// expected-note@*:* {{because 'constructible_from<copyable_non_movable, copyable_non_movable>' evaluated to false}}
87+
// expected-note@*:* {{because 'is_constructible_v<copyable_non_movable, copyable_non_movable>' evaluated to false}}
88+
}
89+
{
90+
int* first = nullptr;
91+
int* last = nullptr;
92+
std::ranges::fold_left_with_iter(first, last, not_convertible_to_int(), std::plus());
93+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, not_convertible_to_int, int *>' evaluated to false}}
94+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, not_convertible_to_int, int *, invoke_result_t<plus<void> &, not_convertible_to_int, iter_reference_t<int *> > >' evaluated to false}}
95+
// expected-note@*:* {{because 'convertible_to<not_convertible_to_int, int>' evaluated to false}}
96+
// expected-note@*:* {{because 'is_convertible_v<not_convertible_to_int, int>' evaluated to false}}
97+
}
98+
{
99+
not_invocable_with_decayed* first;
100+
not_invocable_with_decayed* last;
101+
std::ranges::fold_left_with_iter(first, last, 0, std::plus());
102+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, int, not_invocable_with_decayed *>' evaluated to false}}
103+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, int, not_invocable_with_decayed *, invoke_result_t<plus<void> &, int, iter_reference_t<not_invocable_with_decayed *> > >' evaluated to false}}
104+
// expected-note@*:* {{because 'invocable<std::plus<void> &, not_invocable_with_decayed, iter_reference_t<not_invocable_with_decayed *> >' evaluated to false}}
105+
// expected-note@*:* {{because 'std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)' would be invalid: no matching function for call to 'invoke'}}
106+
}
107+
{
108+
not_assignable_to_decayed* first;
109+
not_assignable_to_decayed* last;
110+
std::ranges::fold_left_with_iter(first, last, not_assignable_to_decayed(), std::plus());
111+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, not_assignable_to_decayed, not_assignable_to_decayed *>' evaluated to false}}
112+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, not_assignable_to_decayed, not_assignable_to_decayed *, invoke_result_t<plus<void> &, not_assignable_to_decayed, iter_reference_t<not_assignable_to_decayed *> > >' evaluated to false}}
113+
// expected-note@*:* {{because 'assignable_from<not_assignable_to_decayed &, invoke_result_t<plus<void> &, not_assignable_to_decayed, iter_reference_t<not_assignable_to_decayed *> > >' evaluated to false}}
114+
// expected-note@*:* {{because '__lhs = std::forward<_Rhs>(__rhs)' would be invalid: no viable overloaded '='}}
115+
}
116+
}
117+
118+
void test_fold_range() {
119+
// expected-note@*:* 9 {{candidate template ignored: constraints not satisfied}}
120+
// expected-note@*:* 9 {{candidate function template not viable: requires 4 arguments, but 3 were provided}}
121+
122+
{
123+
struct bad_range {
124+
bad_iterator_category begin();
125+
std::unreachable_sentinel_t end();
126+
};
127+
128+
bad_range r;
129+
std::ranges::fold_left_with_iter(r, 0, std::plus());
130+
// expected-note@*:* {{because 'bad_range &' does not satisfy 'input_range'}}
131+
// expected-note@*:* {{because 'iterator_t<bad_range &>' (aka 'bad_iterator_category') does not satisfy 'input_iterator'}}
132+
// expected-note@*:* {{because 'derived_from<_ITER_CONCEPT<bad_iterator_category>, input_iterator_tag>' evaluated to false}}
133+
// expected-note@*:* {{because 'is_base_of_v<std::input_iterator_tag, void>' evaluated to false}}
134+
}
135+
{
136+
test_range<cpp20_input_iterator, int> r;
137+
138+
std::ranges::fold_left_with_iter(r, 0, non_copy_constructible_callable());
139+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<non_copy_constructible_callable, int, iterator_t<test_range<cpp20_input_iterator, int> &> >' evaluated to false}}
140+
// expected-note@*:* {{because 'non_copy_constructible_callable' does not satisfy 'copy_constructible'}}
141+
// expected-note@*:* {{because 'constructible_from<non_copy_constructible_callable, non_copy_constructible_callable &>' evaluated to false}}
142+
// expected-note@*:* {{because 'is_constructible_v<non_copy_constructible_callable, non_copy_constructible_callable &>' evaluated to false}}
143+
144+
std::ranges::fold_left_with_iter(r, 0, not_invocable());
145+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<not_invocable, int, iterator_t<test_range<cpp20_input_iterator, int> &> >' evaluated to false}}
146+
// expected-note@*:* {{because 'invocable<not_invocable &, int, iter_reference_t<cpp20_input_iterator<int *> > >' evaluated to false}}
147+
// expected-note@*:* {{because 'std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)' would be invalid: no matching function for call to 'invoke'}}
148+
}
149+
{
150+
test_range<cpp20_input_iterator, S> r;
151+
152+
std::ranges::fold_left_with_iter(r, S(), non_decayable_result());
153+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<non_decayable_result, S, iterator_t<test_range<cpp20_input_iterator, S> &> >' evaluated to false}}
154+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<non_decayable_result, S, cpp20_input_iterator<S *>, invoke_result_t<non_decayable_result &, S, iter_reference_t<cpp20_input_iterator<S *> > > >' evaluated to false}}
155+
// expected-note@*:* {{because 'convertible_to<volatile S &, S>' evaluated to false}}
156+
// expected-note@*:* {{because 'is_convertible_v<volatile S &, S>' evaluated to false}}
157+
}
158+
{
159+
test_range<cpp20_input_iterator, copyable_non_movable> r;
160+
std::ranges::fold_left_with_iter(r, non_movable(), std::plus());
161+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, non_movable, iterator_t<test_range<cpp20_input_iterator, copyable_non_movable> &> >' evaluated to false}}
162+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, non_movable, cpp20_input_iterator<copyable_non_movable *>, invoke_result_t<plus<void> &, non_movable, iter_reference_t<cpp20_input_iterator<copyable_non_movable *> > > >' evaluated to false}}
163+
// expected-note@*:* {{because 'non_movable' does not satisfy 'movable'}}
164+
// expected-note@*:* {{because 'non_movable' does not satisfy 'move_constructible'}}
165+
// expected-note@*:* {{because 'constructible_from<non_movable, non_movable>' evaluated to false}}
166+
// expected-note@*:* {{because 'is_constructible_v<non_movable, non_movable>' evaluated to false}}
167+
}
168+
{
169+
test_range<cpp20_input_iterator, copyable_non_movable> r;
170+
171+
std::ranges::fold_left_with_iter(r, 0, std::minus());
172+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::minus<void>, int, iterator_t<test_range<cpp20_input_iterator, copyable_non_movable> &> >' evaluated to false}}
173+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::minus<void>, int, cpp20_input_iterator<copyable_non_movable *>, invoke_result_t<minus<void> &, int, iter_reference_t<cpp20_input_iterator<copyable_non_movable *> > > >' evaluated to false}}
174+
// expected-note@*:* {{because 'copyable_non_movable' does not satisfy 'movable'}}
175+
// expected-note@*:* {{because 'copyable_non_movable' does not satisfy 'move_constructible'}}
176+
// expected-note@*:* {{because 'constructible_from<copyable_non_movable, copyable_non_movable>' evaluated to false}}
177+
// expected-note@*:* {{because 'is_constructible_v<copyable_non_movable, copyable_non_movable>' evaluated to false}}
178+
}
179+
{
180+
test_range<cpp20_input_iterator, int> r;
181+
std::ranges::fold_left_with_iter(r, not_convertible_to_int(), std::plus());
182+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, not_convertible_to_int, iterator_t<test_range<cpp20_input_iterator, int> &> >' evaluated to false}}
183+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, not_convertible_to_int, cpp20_input_iterator<int *>, invoke_result_t<plus<void> &, not_convertible_to_int, iter_reference_t<cpp20_input_iterator<int *> > > >' evaluated to false}}
184+
// expected-note@*:* {{because 'convertible_to<not_convertible_to_int, int>' evaluated to false}}
185+
// expected-note@*:* {{because 'is_convertible_v<not_convertible_to_int, int>' evaluated to false}}
186+
}
187+
{
188+
test_range<cpp20_input_iterator, not_invocable_with_decayed> r;
189+
std::ranges::fold_left_with_iter(r, 0, std::plus());
190+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, int, iterator_t<test_range<cpp20_input_iterator, not_invocable_with_decayed> &> >' evaluated to false}}
191+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, int, cpp20_input_iterator<not_invocable_with_decayed *>, invoke_result_t<plus<void> &, int, iter_reference_t<cpp20_input_iterator<not_invocable_with_decayed *> > > >' evaluated to false}}
192+
// expected-note@*:* {{because 'invocable<std::plus<void> &, not_invocable_with_decayed, iter_reference_t<cpp20_input_iterator<not_invocable_with_decayed *> > >' evaluated to false}}
193+
// expected-note@*:* {{because 'std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)' would be invalid: no matching function for call to 'invoke'}}
194+
}
195+
{
196+
test_range<cpp20_input_iterator, not_assignable_to_decayed> r;
197+
std::ranges::fold_left_with_iter(r, not_assignable_to_decayed(), std::plus());
198+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, not_assignable_to_decayed, iterator_t<test_range<cpp20_input_iterator, not_assignable_to_decayed> &> >' evaluated to false}}
199+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, not_assignable_to_decayed, cpp20_input_iterator<not_assignable_to_decayed *>, invoke_result_t<plus<void> &, not_assignable_to_decayed, iter_reference_t<cpp20_input_iterator<not_assignable_to_decayed *> > > >' evaluated to false}}
200+
// expected-note@*:* {{because 'assignable_from<not_assignable_to_decayed &, invoke_result_t<plus<void> &, not_assignable_to_decayed, iter_reference_t<cpp20_input_iterator<not_assignable_to_decayed *> > > >' evaluated to false}}
201+
// expected-note@*:* {{because '__lhs = std::forward<_Rhs>(__rhs)' would be invalid: no viable overloaded '='}}
202+
}
203+
}

0 commit comments

Comments
 (0)