[Issue 17927] [scope] scope input return value can be escaped
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 23 04:57:54 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=17927
--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
Changing the @trusted to @safe makes the first example fail to compile with:
test.d(6): Error: pointer slicing not allowed in safe functions
Changing String to:
struct String {
inout(char)[] opSlice() inout scope @safe {
return ptr[];
}
char[] ptr;
}
And it now compiles, as it should. Will look at the rest.
--- Comment #3 from Walter Bright <bugzilla at digitalmars.com> ---
Back to the process of stripping things down to the essentials:
--------------------
const(char)* foo1(scope const(char)* ptr) @safe { return ptr; }
inout(char)* foo2(scope inout(char)* ptr) @safe { return ptr; }
--------------------
Produces the expected error messages:
test.d(1): Error: scope variable ptr may not be returned
test.d(3): Error: scope variable ptr may not be returned
So add in a bit of complexity:
--------------
struct String {
const(char)* mem1() const scope @safe { return ptr; }
inout(char)* mem2() inout scope @safe { return ptr; }
char* ptr;
}
--------------
Produces:
test.d(2): Error: scope variable this may not be returned
The message for mem2() is not generated, so the issue is with the 'inout' on
the 'this' parameter.
--
More information about the Digitalmars-d-bugs
mailing list