d: Merge upstream dmd, druntime 4c18eed967, phobos d945686a4.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test1021.d
blobb3bb5b3ef2cdd05e41b6499906f2e7e0f13cba4e
1 /* REQUIRED_ARGS: -preview=dip1021
2 */
4 @safe:
6 /* TEST_OUTPUT:
7 ---
8 fail_compilation/test1021.d(1009): Error: more than one mutable reference of `p` in arguments to `test1021.fooa()`
9 fail_compilation/test1021.d(1010): Error: mutable and const references of `p` in arguments to `test1021.foob()`
10 fail_compilation/test1021.d(1011): Error: mutable and const references of `p` in arguments to `test1021.fooc()`
11 fail_compilation/test1021.d(1013): Error: more than one mutable reference of `p` in arguments to `test1021.fooe()`
12 ---
15 #line 1000
17 void fooa(int*, int*);
18 void foob(const(int)*, int*);
19 void fooc(int*, const(int)*);
20 void food(const(int)*, const(int)*);
21 void fooe(int*, ...);
23 void test1(int* p)
25 fooa(p, p); // error
26 foob(p, p); // error
27 fooc(p, p); // error
28 food(p, p); // ok
29 fooe(p, p); // error
32 /***********************************/
34 /* TEST_OUTPUT:
35 ---
36 fail_compilation/test1021.d(2010): Error: more than one mutable reference to `i` in arguments to `test1021.fopa()`
37 fail_compilation/test1021.d(2011): Error: mutable and const references to `i` in arguments to `test1021.fopb()`
38 fail_compilation/test1021.d(2012): Error: mutable and const references to `i` in arguments to `test1021.fopc()`
39 fail_compilation/test1021.d(2014): Error: more than one mutable reference to `i` in arguments to `test1021.fope()`
40 ---
43 #line 2000
45 void fopa(ref int, scope int*);
46 void fopb(ref int, scope const int*);
47 void fopc(ref const int, scope int*);
48 void fopd(ref const int, scope const int*);
49 inout(int) fope(ref inout int, scope int*);
50 void test2()
52 int i;
53 @trusted int* toPtr(ref int i) { return &i; }
54 fopa(i, toPtr(i)); // error
55 fopb(i, toPtr(i)); // error
56 fopc(i, toPtr(i)); // error
57 fopd(i, toPtr(i)); // ok
58 fope(i, toPtr(i)); // error
61 /***********************************/
63 /* TEST_OUTPUT:
64 ---
65 fail_compilation/test1021.d(3015): Error: more than one mutable reference to `s` in arguments to `test1021.S.method()`
66 fail_compilation/test1021.d(3019): Error: more than one mutable reference of `c` in arguments to `test1021.C.method()`
67 ---
70 #line 3000
72 struct S
74 void method(ref S s);
77 class C
79 void method(C c);
82 void test3()
84 S s;
85 S* ps;
86 s.method(s); // error
87 ps.method(s); // ok
89 C c;
90 c.method(c); // error
93 /***********************************/
95 /* TEST_OUTPUT:
96 ---
97 fail_compilation/test1021.d(4008): Error: more than one mutable reference to `i` in arguments to `test1021.test4.nested()`
98 ---
101 #line 4000
103 void test4()
105 int i, k;
106 int nested(ref int j)
108 return i + j;
110 nested(i); // error
111 nested(k); // ok
114 /***********************************/
116 /* TEST_OUTPUT:
118 fail_compilation/test1021.d(5012): Error: more than one mutable reference of `s` in arguments to `test1021.foo5()`
122 #line 5000
124 struct S5
126 int i;
127 int* p;
130 void foo5(S5, S5);
132 void test5()
134 S5 s;
135 foo5(s, s);
138 alias A5 = void delegate() const;
140 void foo5(A5, A5);
142 void test5a()
144 A5 a;
145 foo5(a, a);
148 alias B5 = void function();
150 void foo5(B5, B5);
152 void test5b()
154 B5 b;
155 foo5(b, b);
158 struct S5c
160 void function() fp;
163 void foo5(S5c, S5c);
165 void test5c()
167 S5c s;
168 foo5(s, s);