| 1 |
/* REQUIRED_ARGS: -verrors=0 |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/diag9679.d(93): Deprecation: `auto` and `ref` storage classes should be adjacent |
| 5 |
fail_compilation/diag9679.d(93): Deprecation: `auto` and `ref` storage classes should be adjacent |
| 6 |
fail_compilation/diag9679.d(15): Error: rvalue `1` cannot be assigned to `ref n` |
| 7 |
fail_compilation/diag9679.d(16): Error: variable `diag9679.main.n` - storage class `auto` has no effect if type is not inferred, did you mean `scope`? |
| 8 |
fail_compilation/diag9679.d(17): Error: variable `diag9679.main.S.a` - field declarations cannot be `ref` |
| 9 |
fail_compilation/diag9679.d(24): Error: returning `r` escapes a reference to local variable `i` |
| 10 |
--- |
| 11 |
*/ |
| 12 |
|
| 13 |
void main() |
| 14 |
{ |
| 15 |
if (ref n = 1) {} |
| 16 |
if (auto int n = 1) {} |
| 17 |
struct S { ref int a; } |
| 18 |
} |
| 19 |
|
| 20 |
ref int test2() |
| 21 |
{ |
| 22 |
int i; |
| 23 |
ref r = i; |
| 24 |
return r; |
| 25 |
} |
| 26 |
|
| 27 |
ref int test3() |
| 28 |
{ |
| 29 |
extern int i; |
| 30 |
ref r = i; |
| 31 |
return r; |
| 32 |
} |
| 33 |
|
| 34 |
struct S { int a; } |
| 35 |
|
| 36 |
void test4() |
| 37 |
{ |
| 38 |
S s; |
| 39 |
ref int r1 = s.a; |
| 40 |
r1 = 3; |
| 41 |
__gshared S t2; |
| 42 |
ref int r2 = t2.a; |
| 43 |
static S t3; |
| 44 |
ref int r3 = t3.a; |
| 45 |
extern S t4; |
| 46 |
ref int r4 = t4.a; |
| 47 |
} |
| 48 |
|
| 49 |
/* TEST_OUTPUT: |
| 50 |
--- |
| 51 |
fail_compilation/diag9679.d(66): Error: variable `diag9679.test5.r5` - initializer is required for `ref` variable |
| 52 |
fail_compilation/diag9679.d(66): Error: rvalue `0` cannot be assigned to `ref r5` |
| 53 |
fail_compilation/diag9679.d(71): Error: rvalue `4` cannot be assigned to `ref x` |
| 54 |
fail_compilation/diag9679.d(72): Error: returning `x` escapes a reference to local variable `x` |
| 55 |
fail_compilation/diag9679.d(77): Error: type `immutable(int)` cannot be assigned to `ref int x` |
| 56 |
fail_compilation/diag9679.d(84): Error: returning `x` escapes a reference to local variable `x` |
| 57 |
fail_compilation/diag9679.d(89): Error: variable `diag9679.test9.x` - void initializer not allowed for `ref` variable |
| 58 |
fail_compilation/diag9679.d(90): Error: variable `diag9679.test9.y` - void initializer not allowed for `ref` variable |
| 59 |
fail_compilation/diag9679.d(96): Error: variable `x` - `auto ref` variable must have `auto` and `ref` adjacent |
| 60 |
--- |
| 61 |
*/ |
| 62 |
|
| 63 |
|
| 64 |
void test5() |
| 65 |
{ |
| 66 |
ref int r5; |
| 67 |
} |
| 68 |
|
| 69 |
ref int test6() |
| 70 |
{ |
| 71 |
ref int x = 4; |
| 72 |
return x; |
| 73 |
} |
| 74 |
|
| 75 |
void test7(immutable int y) |
| 76 |
{ |
| 77 |
ref int x = y; |
| 78 |
x = 5; |
| 79 |
} |
| 80 |
|
| 81 |
ref int test8() |
| 82 |
{ |
| 83 |
auto ref int x = 3; |
| 84 |
return x; |
| 85 |
} |
| 86 |
|
| 87 |
void test9() |
| 88 |
{ |
| 89 |
ref int x = void; |
| 90 |
auto ref int y = void; |
| 91 |
} |
| 92 |
|
| 93 |
void testKeywordOrder()(ref auto int x, auto const ref float y) {} |
| 94 |
void testKeywordOrder() |
| 95 |
{ |
| 96 |
ref auto int x = 3; |
| 97 |
} |