Skip to content

Commit

Permalink
fix Issue 17927 - [scope] parameter value can be escaped via return
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Oct 23, 2017
1 parent 86cab37 commit 3f7544f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/fail_compilation/fail17927.d
@@ -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; }

0 comments on commit 3f7544f

Please sign in to comment.