Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/fail20033.d

raw
1 // REQUIRED_ARGS: -de
2 /*
3 TEST_OUTPUT:
4 ---
5 fail_compilation/fail20033.d(38): Deprecation: `alias byKeyValue this` is deprecated - This was a bad idea
6 fail_compilation/fail20033.d(39): Deprecation: `alias byKeyValue this` is deprecated
7 fail_compilation/fail20033.d(41): Deprecation: `alias byKeyValue this` is deprecated - This was a bad idea
8 fail_compilation/fail20033.d(42): Deprecation: `alias byKeyValue this` is deprecated
9 ---
10 */
11 #line 1
12 struct Tuple(T...)
13 {
14 T values;
15 alias values this;
16 }
17
18 alias KVT = Tuple!(string, string);
19
20 struct Test {
21 struct Range {
22 bool empty () { return false; }
23 KVT front() { return KVT.init; }
24 void popFront() {}
25 }
26
27 auto byKeyValue () { return Range.init; }
28
29 deprecated("This was a bad idea")
30 alias byKeyValue this;
31 }
32
33 struct Test2 {
34 struct Range {
35 bool empty () { return false; }
36 KVT front() { return KVT.init; }
37 void popFront() {}
38 }
39
40 auto byKeyValue () { return Range.init; }
41
42 deprecated alias byKeyValue this;
43 }
44
45 void main ()
46 {
47 foreach (k, v; Test.init.byKeyValue) {} // Fine
48 foreach (k, v; Test2.init.byKeyValue) {} // Fine
49 foreach (k, v; Test.init) {} // Fails
50 foreach (k, v; Test2.init) {} // Fails
51
52 auto f1 = Test.init.front(); // Fails
53 auto f2 = Test2.init.front(); // Fails
54 }