Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Issue 17927 - [scope] parameter value can be escaped via return
- Loading branch information
1 parent
86cab37
commit 3f7544f
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* REQUIRED_ARGS: -dip1000 | ||
* TEST_OUTPUT: | ||
--- | ||
fail_compilation/fail17927.d(13): Error: scope variable `this` may not be returned | ||
fail_compilation/fail17927.d(21): Error: scope variable `ptr` may not be returned | ||
fail_compilation/fail17927.d(23): Error: scope variable `ptr` may not be returned | ||
--- | ||
*/ | ||
|
||
// https://issues.dlang.org/show_bug.cgi?id=17927 | ||
|
||
struct String { | ||
const(char)* mem1() const scope @safe { return ptr; } | ||
|
||
inout(char)* mem2() inout scope @safe { return ptr; } // no error because `ref inout` implies `return` | ||
|
||
char* ptr; | ||
} | ||
|
||
|
||
const(char)* foo1(scope const(char)* ptr) @safe { return ptr; } | ||
|
||
inout(char)* foo2(scope inout(char)* ptr) @safe { return ptr; } | ||
|