]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/fail_compilation/test15191.d
d: Merge upstream dmd 3982604c5, druntime bc58b1e9, phobos 12329adb6.
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test15191.d
CommitLineData
b4c522fa 1/* TEST_OUTPUT:
9c7d5e88 2PERMUTE_ARGS -dip1000
b4c522fa 3---
9c7d5e88
IB
4fail_compilation/test15191.d(31): Error: returning `&identity(x)` escapes a reference to local variable `x`
5fail_compilation/test15191.d(37): Error: returning `&identityPtr(x)` escapes a reference to local variable `x`
6fail_compilation/test15191.d(43): Error: cannot take address of `ref return` of `identityPtr()` in `@safe` function `addrOfRefTransitive`
7fail_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:
15ref int foo(return ref int s)
b4c522fa
IB
16{
17 return s;
18}
19
9c7d5e88 20int* bar(return ref int s)
b4c522fa
IB
21{
22 return &foo(s);
23}
9c7d5e88
IB
24
25ref int identity(ref return int x) {return x;}
26ref int* identityPtr(ref return int* x) {return x;}
27
28int* addrOfRefEscape()
29{
30 int x;
31 return &identity(x);
32}
33
34int** addrOfRefSystem() @system
35{
36 int* x;
37 return &identityPtr(x);
38}
39
40int** addrOfRefTransitive()
41{
42 int* x;
43 return &identityPtr(x);
44}
45
46int gInt;
47ref int getGlobalInt() {return gInt;}
48
49int* addrOfRefGlobal()
50{
51 return &getGlobalInt();
52}