]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/fail_compilation/ice12174.d
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / ice12174.d
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/ice12174.d(12): Error: no property 'sum' for type 'int[]'
5 fail_compilation/ice12174.d(20): Error: CTFE failed because of previous errors in this
6 fail_compilation/ice12174.d(13): called from here: filter([1, 2, 3])
7 ---
8 */
9
10 void main()
11 {
12 enum foo3 = (int n) => [1,2,3].sum;
13 enum bar3 = [1,2,3].filter!(n => n % foo3(n) == 0);
14 }
15
16 template filter(alias pred)
17 {
18 auto filter(Range)(Range rs)
19 {
20 return FilterResult!(pred, Range)(rs);
21 }
22 }
23
24 private struct FilterResult(alias pred, R)
25 {
26 R _input;
27
28 this(R r)
29 {
30 _input = r;
31 while (_input.length && !pred(_input[0]))
32 {
33 _input = _input[1..$];
34 }
35 }
36
37 @property bool empty() { return _input.length == 0; }
38
39 @property auto ref front()
40 {
41 return _input[0];
42 }
43
44 void popFront()
45 {
46 do
47 {
48 _input = _input[1..$];
49 } while (_input.length && !pred(_input[0]));
50 }
51 }