Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/test22840.d

raw
1 /* REQUIRED_ARGS: -preview=dip1000
2 * TEST_OUTPUT:
3 ---
4 fail_compilation/test22840.d(25): Error: returning `sb.slice()` escapes a reference to local variable `sb`
5 ---
6 */
7
8 // inout method with inferred @safe escapes local data
9 // https://issues.dlang.org/show_bug.cgi?id=22840
10
11 // See also: https://issues.dlang.org/show_bug.cgi?id=20149
12
13 struct S
14 {
15 int buf;
16 auto slice() inout
17 {
18 return &buf;
19 }
20 }
21
22 int* fun() @safe
23 {
24 S sb;
25 return sb.slice(); // should error
26 }