| 1 |
/* REQUIRED_ARGS: -preview=dip1021 |
| 2 |
*/ |
| 3 |
|
| 4 |
@safe: |
| 5 |
|
| 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 |
--- |
| 13 |
*/ |
| 14 |
|
| 15 |
#line 1000 |
| 16 |
|
| 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*, ...); |
| 22 |
|
| 23 |
void test1(int* p) |
| 24 |
{ |
| 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 |
| 30 |
} |
| 31 |
|
| 32 |
/***********************************/ |
| 33 |
|
| 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 |
--- |
| 41 |
*/ |
| 42 |
|
| 43 |
#line 2000 |
| 44 |
|
| 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() |
| 51 |
{ |
| 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 |
| 59 |
} |
| 60 |
|
| 61 |
/***********************************/ |
| 62 |
|
| 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 |
--- |
| 68 |
*/ |
| 69 |
|
| 70 |
#line 3000 |
| 71 |
|
| 72 |
struct S |
| 73 |
{ |
| 74 |
void method(ref S s); |
| 75 |
} |
| 76 |
|
| 77 |
class C |
| 78 |
{ |
| 79 |
void method(C c); |
| 80 |
} |
| 81 |
|
| 82 |
void test3() |
| 83 |
{ |
| 84 |
S s; |
| 85 |
S* ps; |
| 86 |
s.method(s); // error |
| 87 |
ps.method(s); // ok |
| 88 |
|
| 89 |
C c; |
| 90 |
c.method(c); // error |
| 91 |
} |
| 92 |
|
| 93 |
/***********************************/ |
| 94 |
|
| 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 |
--- |
| 99 |
*/ |
| 100 |
|
| 101 |
#line 4000 |
| 102 |
|
| 103 |
void test4() |
| 104 |
{ |
| 105 |
int i, k; |
| 106 |
int nested(ref int j) |
| 107 |
{ |
| 108 |
return i + j; |
| 109 |
} |
| 110 |
nested(i); // error |
| 111 |
nested(k); // ok |
| 112 |
} |
| 113 |
|
| 114 |
/***********************************/ |
| 115 |
|
| 116 |
/* TEST_OUTPUT: |
| 117 |
--- |
| 118 |
fail_compilation/test1021.d(5012): Error: more than one mutable reference of `s` in arguments to `test1021.foo5()` |
| 119 |
--- |
| 120 |
*/ |
| 121 |
|
| 122 |
#line 5000 |
| 123 |
|
| 124 |
struct S5 |
| 125 |
{ |
| 126 |
int i; |
| 127 |
int* p; |
| 128 |
} |
| 129 |
|
| 130 |
void foo5(S5, S5); |
| 131 |
|
| 132 |
void test5() |
| 133 |
{ |
| 134 |
S5 s; |
| 135 |
foo5(s, s); |
| 136 |
} |
| 137 |
|
| 138 |
alias A5 = void delegate() const; |
| 139 |
|
| 140 |
void foo5(A5, A5); |
| 141 |
|
| 142 |
void test5a() |
| 143 |
{ |
| 144 |
A5 a; |
| 145 |
foo5(a, a); |
| 146 |
} |
| 147 |
|
| 148 |
alias B5 = void function(); |
| 149 |
|
| 150 |
void foo5(B5, B5); |
| 151 |
|
| 152 |
void test5b() |
| 153 |
{ |
| 154 |
B5 b; |
| 155 |
foo5(b, b); |
| 156 |
} |
| 157 |
|
| 158 |
struct S5c |
| 159 |
{ |
| 160 |
void function() fp; |
| 161 |
} |
| 162 |
|
| 163 |
void foo5(S5c, S5c); |
| 164 |
|
| 165 |
void test5c() |
| 166 |
{ |
| 167 |
S5c s; |
| 168 |
foo5(s, s); |
| 169 |
} |