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