]>
Commit | Line | Data |
---|---|---|
b4c522fa | 1 | /* TEST_OUTPUT: |
9c7d5e88 | 2 | PERMUTE_ARGS -dip1000 |
b4c522fa | 3 | --- |
9c7d5e88 IB |
4 | fail_compilation/test15191.d(31): Error: returning `&identity(x)` escapes a reference to local variable `x` |
5 | fail_compilation/test15191.d(37): Error: returning `&identityPtr(x)` escapes a reference to local variable `x` | |
6 | fail_compilation/test15191.d(43): Error: cannot take address of `ref return` of `identityPtr()` in `@safe` function `addrOfRefTransitive` | |
7 | fail_compilation/test15191.d(43): Error: returning `&identityPtr(x)` escapes a reference to local variable `x` | |
b4c522fa IB |
8 | --- |
9 | */ | |
10 | ||
b4c522fa | 11 | // https://issues.dlang.org/show_bug.cgi?id=15191 |
9c7d5e88 | 12 | // https://issues.dlang.org/show_bug.cgi?id=22519 |
b4c522fa | 13 | |
9c7d5e88 IB |
14 | @safe: |
15 | ref int foo(return ref int s) | |
b4c522fa IB |
16 | { |
17 | return s; | |
18 | } | |
19 | ||
9c7d5e88 | 20 | int* bar(return ref int s) |
b4c522fa IB |
21 | { |
22 | return &foo(s); | |
23 | } | |
9c7d5e88 IB |
24 | |
25 | ref int identity(ref return int x) {return x;} | |
26 | ref int* identityPtr(ref return int* x) {return x;} | |
27 | ||
28 | int* addrOfRefEscape() | |
29 | { | |
30 | int x; | |
31 | return &identity(x); | |
32 | } | |
33 | ||
34 | int** addrOfRefSystem() @system | |
35 | { | |
36 | int* x; | |
37 | return &identityPtr(x); | |
38 | } | |
39 | ||
40 | int** addrOfRefTransitive() | |
41 | { | |
42 | int* x; | |
43 | return &identityPtr(x); | |
44 | } | |
45 | ||
46 | int gInt; | |
47 | ref int getGlobalInt() {return gInt;} | |
48 | ||
49 | int* addrOfRefGlobal() | |
50 | { | |
51 | return &getGlobalInt(); | |
52 | } |