| 1 |
/* |
| 2 |
REQUIRED_ARGS: |
| 3 |
TEST_OUTPUT: |
| 4 |
--- |
| 5 |
fail_compilation/dip25.d(17): Error: escaping a reference to parameter `this` by returning `this.buffer[]` is not allowed in a `@safe` function |
| 6 |
fail_compilation/dip25.d(15): perhaps annotate the function with `return` |
| 7 |
fail_compilation/dip25.d(22): Error: returning `identity(x)` escapes a reference to parameter `x` |
| 8 |
fail_compilation/dip25.d(23): Error: escaping a reference to parameter `x` by returning `identity(x)` is not allowed in a `@safe` function |
| 9 |
fail_compilation/dip25.d(23): perhaps annotate the parameter with `return` |
| 10 |
--- |
| 11 |
*/ |
| 12 |
struct Data |
| 13 |
{ |
| 14 |
char[256] buffer; |
| 15 |
@property const(char)[] filename() const pure nothrow @safe |
| 16 |
{ |
| 17 |
return buffer[]; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
ref int identity(return ref int x) @safe { return x; } |
| 22 |
ref int fun(return int x) @safe { return identity(x); } |
| 23 |
ref int fun2(ref int x) @safe { return identity(x); } |
| 24 |
|
| 25 |
void main() |
| 26 |
{ |
| 27 |
Data d; |
| 28 |
const f = d.filename; |
| 29 |
} |