[Issue 17927] New: [scope] scope input return value can be escaped
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Oct 22 17:16:42 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=17927
Issue ID: 17927
Summary: [scope] scope input return value can be escaped
Product: D
Version: D2
Hardware: All
OS: Linux
Status: NEW
Keywords: safe
Severity: normal
Priority: P4
Component: dmd
Assignee: bugzilla at digitalmars.com
Reporter: code at dawg.eu
cat > bug.d << CODE
struct String
{
pure nothrow @nogc:
inout(char)[] opSlice() inout scope @trusted
{
return ptr[0 .. len];
}
char *ptr;
size_t len;
}
void escape(const char[] s) nothrow @safe @nogc
{
static const(char)[] cache;
cache = s;
}
///
nothrow @safe
unittest
{
auto s = String(&"Hello".dup[0], 5);
escape(s[]);
}
CODE
dmd -c -unittest -dip1000 bug.d
----
Should error with `scope variable this.ptr may not be returned`.
workaround:
----
char[] opSlice() scope @trusted
{
return ptr[0 .. len];
}
const(char)[] opSlice() const scope @trusted
{
return ptr[0 .. len];
}
----
--
More information about the Digitalmars-d-bugs
mailing list