Debian Codegraph @

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

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/fail_arrayexp.d(24): Error: cannot use `[]` operator on expression of type `int`
5 fail_compilation/fail_arrayexp.d(25): Error: cannot use `[]` operator on expression of type `void`
6 fail_compilation/fail_arrayexp.d(26): Error: static array of `const(int)[]` with multiple lengths not allowed
7 fail_compilation/fail_arrayexp.d(27): Error: only one index allowed to index `string`
8 fail_compilation/fail_arrayexp.d(28): Error: no `[]` operator overload for type `U`
9 fail_compilation/fail_arrayexp.d(16): perhaps define `auto opIndex() {}` for `fail_arrayexp.U`
10 fail_compilation/fail_arrayexp.d(29): Error: only one index allowed to index `(int, string)`
11 ---
12 */
13
14 int i;
15 string str;
16 union U {}
17 alias typeAlias = const(int)[];
18 void getVoid();
19 alias getTuple(T...) = T;
20
21 void test19534() // https://issues.dlang.org/show_bug.cgi?id=19534
22 {
23 U agg;
24 #line 24
25 auto p = i[0];
26 auto q = getVoid()[0];
27 alias r = getTuple!(typeAlias[0, 1]);
28 auto s = str[0, 1, 2];
29 auto t = agg[];
30 auto u = getTuple!(int, string)[1, 2];
31 }
32
33 /*
34 TEST_OUTPUT:
35 ---
36 fail_compilation/fail_arrayexp.d(49): Error: no `[3.."4"]` operator overload for type `S`
37 fail_compilation/fail_arrayexp.d(42): perhaps define `auto opSlice(int lower, string upper) {}` for `fail_arrayexp.S`
38 fail_compilation/fail_arrayexp.d(50): Error: no `[]` operator overload for type `S`
39 fail_compilation/fail_arrayexp.d(42): perhaps define `auto opIndex(int, string, char) {}` for `fail_arrayexp.S`
40 ---
41 */
42
43 struct S
44 {
45 }
46
47 void testSlice()
48 {
49 S s;
50 const b = s[3 .. "4"];
51 const c = s[3, "4", 'c'];
52 }