File: checked_iterators_unittest.nc

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (325 lines) | stat: -rw-r--r-- 11,353 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is a "No Compile Test" suite.
// http://dev.chromium.org/developers/testing/no-compile-tests

#include "base/containers/checked_iterators.h"

namespace base {

#if defined(NCTEST_CHECKED_ITERATORS_CONSTRUCTOR_START_END)  // [r"constexpr variable 'iter' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // start can't be larger than end
  constexpr CheckedContiguousIterator<const int> iter(kArray + 1, kArray);
}

#elif defined(NCTEST_CHECKED_ITERATORS_CONSTRUCTOR_START_CURRENT)  // [r"constexpr variable 'iter' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // current can't be larger than start
  constexpr CheckedContiguousIterator<const int> iter(kArray + 1, kArray, kArray + 5);
}

#elif defined(NCTEST_CHECKED_ITERATORS_CONSTRUCTOR_CURRENT_END)  // [r"constexpr variable 'iter' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // current can't be larger than end
  constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 2, kArray + 1);
}

#elif defined(NCTEST_CHECKED_ITERATORS_EQ_DIFFERENT_ITER)  // [r"constexpr variable 'equal' must be initialized by a constant expression"]

constexpr int kArray1[] = {1, 2, 3, 4, 5};
constexpr int kArray2[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't compare iterators into different containers
  constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
  constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
  constexpr bool equal = iter1 == iter2;
}

#elif defined(NCTEST_CHECKED_ITERATORS_NE_DIFFERENT_ITER)  // [r"constexpr variable 'not_equal' must be initialized by a constant expression"]

constexpr int kArray1[] = {1, 2, 3, 4, 5};
constexpr int kArray2[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't compare iterators into different containers
  constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
  constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
  constexpr bool not_equal = iter1 != iter2;
}

#elif defined(NCTEST_CHECKED_ITERATORS_LT_DIFFERENT_ITER)  // [r"constexpr variable 'less_than' must be initialized by a constant expression"]

constexpr int kArray1[] = {1, 2, 3, 4, 5};
constexpr int kArray2[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't compare iterators into different containers
  constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
  constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
  constexpr bool less_than = iter1 < iter2;
}

#elif defined(NCTEST_CHECKED_ITERATORS_LE_DIFFERENT_ITER)  // [r"constexpr variable 'less_equal' must be initialized by a constant expression"]

constexpr int kArray1[] = {1, 2, 3, 4, 5};
constexpr int kArray2[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't compare iterators into different containers
  constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
  constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
  constexpr bool less_equal = iter1 <= iter2;
}

#elif defined(NCTEST_CHECKED_ITERATORS_GT_DIFFERENT_ITER)  // [r"constexpr variable 'greater_than' must be initialized by a constant expression"]

constexpr int kArray1[] = {1, 2, 3, 4, 5};
constexpr int kArray2[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't compare iterators into different containers
  constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
  constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
  constexpr bool greater_than = iter1 > iter2;
}

#elif defined(NCTEST_CHECKED_ITERATORS_GE_DIFFERENT_ITER)  // [r"constexpr variable 'greater_equal' must be initialized by a constant expression"]

constexpr int kArray1[] = {1, 2, 3, 4, 5};
constexpr int kArray2[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't compare iterators into different containers
  constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
  constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
  constexpr bool greater_equal = iter1 >= iter2;
}

#elif defined(NCTEST_CHECKED_ITERATORS_PRE_INCR_END)  // [r"constexpr variable 'pre_incr' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

constexpr int PreIncr() {
  // Can't pre-increment the end iterator.
  CheckedContiguousIterator<const int> end_iter(kArray, kArray + 5, kArray + 5);
  ++end_iter;
  return 0;
}

void WontCompile() {
  constexpr int pre_incr = PreIncr();
}

#elif defined(NCTEST_CHECKED_ITERATORS_POST_INCR_END)  // [r"constexpr variable 'post_incr' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

constexpr int PostIncr() {
  // Can't post-increment the end iterator.
  CheckedContiguousIterator<const int> end_iter(kArray, kArray + 5, kArray + 5);
  end_iter++;
  return 0;
}

void WontCompile() {
  constexpr int post_incr = PostIncr();
}

#elif defined(NCTEST_CHECKED_ITERATORS_PRE_DECR_BEGIN)  // [r"constexpr variable 'pre_decr' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

constexpr int PreDecr() {
  // Can't pre-decrement the begin iterator.
  CheckedContiguousIterator<const int> begin_iter(kArray, kArray + 5);
  --begin_iter;
  return 0;
}

void WontCompile() {
  constexpr int pre_decr = PreDecr();
}

#elif defined(NCTEST_CHECKED_ITERATORS_POST_DECR_BEGIN)  // [r"constexpr variable 'post_decr' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

constexpr int PostDecr() {
  // Can't post-decrement the begin iterator.
  CheckedContiguousIterator<const int> begin_iter(kArray, kArray + 5);
  begin_iter--;
  return 0;
}

void WontCompile() {
  constexpr int post_decr = PostDecr();
}

#elif defined(NCTEST_CHECKED_ITERATORS_INCR_PAST_END)  // [r"constexpr variable 'incr_past_end' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

constexpr int IncrPastEnd() {
  // Can't increment iterator past the end.
  CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  iter += 6;
  return 0;
}

void WontCompile() {
  constexpr int incr_past_end = IncrPastEnd();
}

#elif defined(NCTEST_CHECKED_ITERATORS_DECR_PAST_BEGIN)  // [r"constexpr variable 'decr_past_begin' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

constexpr int DecrPastBegin() {
  // Can't decrement iterator past the begin.
  CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  iter += -1;
  return 0;
}

void WontCompile() {
  constexpr int decr_past_begin = DecrPastBegin();
}

#elif defined(NCTEST_CHECKED_ITERATORS_INCR_PAST_END_2)  // [r"constexpr variable 'iter_past_end' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't increment iterator past the end.
  constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  constexpr auto iter_past_end = iter + 6;
}

#elif defined(NCTEST_CHECKED_ITERATORS_DECR_PAST_BEGIN_2)  // [r"constexpr variable 'iter_past_begin' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't decrement iterator past the begin.
  constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  constexpr auto iter_past_begin = iter + (-1);
}

#elif defined(NCTEST_CHECKED_ITERATORS_DECR_PAST_BEGIN_3)  // [r"constexpr variable 'decr_past_begin' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

constexpr int DecrPastBegin() {
  // Can't decrement iterator past the begin.
  CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  iter -= 1;
  return 0;
}

void WontCompile() {
  constexpr int decr_past_begin = DecrPastBegin();
}

#elif defined(NCTEST_CHECKED_ITERATORS_INCR_PAST_END_3)  // [r"constexpr variable 'incr_past_end' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

constexpr int IncrPastEnd() {
  // Can't increment iterator past the end.
  CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  iter -= (-6);
  return 0;
}

void WontCompile() {
  constexpr int incr_past_end = IncrPastEnd();
}

#elif defined(NCTEST_CHECKED_ITERATORS_DECR_PAST_BEGIN_4)  // [r"constexpr variable 'iter_past_begin' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't decrement iterator past the begin.
  constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  constexpr auto iter_past_begin = iter - 1;
}

#elif defined(NCTEST_CHECKED_ITERATORS_INCR_PAST_END_4)  // [r"constexpr variable 'iter_past_end' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't increment iterator past the end.
  constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  constexpr auto iter_past_end = iter - (-6);
}

#elif defined(NCTEST_CHECKED_ITERATORS_DIFFERENCE_DIFFERENT_ITER)  // [r"constexpr variable 'difference' must be initialized by a constant expression"]

constexpr int kArray1[] = {1, 2, 3, 4, 5};
constexpr int kArray2[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't compare iterators into different containers
  constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
  constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
  constexpr auto difference = iter1 - iter2;
}

#elif defined(NCTEST_CHECKED_ITERATORS_STAR_END)  // [r"constexpr variable 'ref' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't dereference the end iterator by star.
  constexpr CheckedContiguousIterator<const int> end_iter(kArray, kArray + 5, kArray + 5);
  constexpr auto& ref = *end_iter;
}

#elif defined(NCTEST_CHECKED_ITERATORS_ARROW_END)  // [r"constexpr variable 'ptr' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't dereference the end iterator by arrow.
  constexpr CheckedContiguousIterator<const int> end_iter(kArray, kArray + 5, kArray + 5);
  constexpr auto* ptr = end_iter.operator->();
}

#elif defined(NCTEST_CHECKED_ITERATORS_NEGATIVE_OPERATOR_AT)  // [r"constexpr variable 'ref' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't use a negative index in operator[].
  constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  constexpr auto& ref = iter[-1];
}

#elif defined(NCTEST_CHECKED_ITERATORS_OPERATOR_AT_END)  // [r"constexpr variable 'ref' must be initialized by a constant expression"]

constexpr int kArray[] = {1, 2, 3, 4, 5};

void WontCompile() {
  // Can't use a operator[] to deref the end.
  constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
  constexpr auto& ref = iter[5];
}

#endif

}  // namespace base