]> git.ipfire.org Git - thirdparty/gcc.git/blob - 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
1 /* TEST_OUTPUT:
2 PERMUTE_ARGS -dip1000
3 ---
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`
8 ---
9 */
10
11 // https://issues.dlang.org/show_bug.cgi?id=15191
12 // https://issues.dlang.org/show_bug.cgi?id=22519
13
14 @safe:
15 ref int foo(return ref int s)
16 {
17 return s;
18 }
19
20 int* bar(return ref int s)
21 {
22 return &foo(s);
23 }
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 }