[Issue 19183] New: DIP1000 defeated if auto used instead of scope in variable declaration with template this member function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 20 13:08:01 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19183
Issue ID: 19183
Summary: DIP1000 defeated if auto used instead of scope in
variable declaration with template this member
function
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: atila.neves at gmail.com
The code:
--------------------
@safe:
const(int)* gInts;
void main() {
auto s = MyStruct(10);
gInts = s.ints;
}
struct MyStruct
{
import core.stdc.stdlib;
int* ints;
this(int size) @trusted { ints = cast(int*) malloc(size); }
~this() scope @trusted { free(ints); }
scope ptr(this This)() { return ints; }
}
--------------------
This compiles with dip1000 and the code is allowed to escape the reference to
ints even though it shouldn't. Writing out 3 member functions by hand for
mutable, const and immutable works as intended.
Even more strangely, this code can be made to _not_ compile by changing `auto s
= MyStruct(10)` to `scope s = MyStruct(10)` _or_ by adding `scope` to the
destructor. In either of those cases, the code fails to compile with an error
message about escaping, which is the correct behaviour.
--
More information about the Digitalmars-d-bugs
mailing list