MATCH: Improve `A CMP 0 ? A : -A` set of patterns to use bitwise_equal_p.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test15191.d
blobfbbc1c0fa88a3c248ea3da56d65f301155d8cfc7
1 /* TEST_OUTPUT:
2 REQUIRED_ARGS: -preview=dip1000
3 ---
4 fail_compilation/test15191.d(34): Error: returning `&identity(x)` escapes a reference to local variable `x`
5 fail_compilation/test15191.d(40): Error: returning `&identityPtr(x)` escapes a reference to local variable `x`
6 fail_compilation/test15191.d(46): Error: returning `&identityPtr(x)` escapes a reference to local variable `x`
7 fail_compilation/test15191.d(67): Error: cannot take address of `scope` variable `x` since `scope` applies to first indirection only
8 fail_compilation/test15191.d(69): Error: cannot take address of `scope` variable `x` since `scope` applies to first indirection only
9 ---
12 // Test taking the address of a `ref return` using & and [] operators
13 // https://issues.dlang.org/show_bug.cgi?id=15191
14 // https://issues.dlang.org/show_bug.cgi?id=22519
15 // https://issues.dlang.org/show_bug.cgi?id=22539
17 @safe:
18 ref int foo(return ref int s)
20 return s;
23 int* bar(return ref int s)
25 return &foo(s);
28 ref int identity(ref return int x) {return x;}
29 ref int* identityPtr(ref return int* x) {return x;}
31 int* addrOfRefEscape()
33 int x;
34 return &identity(x);
37 int** addrOfRefSystem() @system
39 int* x;
40 return &identityPtr(x);
43 int** addrOfRefTransitive()
45 int* x;
46 return &identityPtr(x);
49 int gInt;
50 ref int getGlobalInt() {return gInt;}
52 int* addrOfRefGlobal()
54 return &getGlobalInt();
57 // Slice:
58 ref int*[1] identityArr(return ref scope int*[1] x)
60 return x;
63 int*[] sliceOfRefEscape()
65 int stackVar = 0xFF;
66 scope int*[1] x = [&stackVar];
67 auto y = identityArr(x)[]; // check transitive scope in assignment
68 cast(void) y;
69 return identityArr(x)[]; // check transitive scope in return statement
72 // https://issues.dlang.org/show_bug.cgi?id=23079
73 int** p;
75 ref int* get() @safe
77 return *p;
80 int** g1() @safe
82 return &get();