← Back to index
|
Original Bugzilla link
Bug 14648 – DIP25's "return" attribute breaks safety checks
Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-06-04T00:03:00Z
Last change time
2016-06-19T02:14:54Z
Keywords
safe
Assigned to
nobody
Creator
briancschott
Comments
Comment #0
by briancschott — 2015-06-04T00:03:18Z
https://gist.github.com/Hackerpilot/d665a0d5c80ddc163454
This code compiles, runs, and segfaults despite being marked @safe. If the `return` attribute is removed from `opSlice` the code will correctly fail to compile.
Comment #1
by bugzilla — 2016-06-07T05:34:23Z
The code in question: // rdmd -unittest -main -dip25 dip25.d private struct Container { this(int c) @safe { arr = new int[](c); arr[] = c; } ~this() @safe { arr[] = -1; } ref Range opSlice() return @safe // remove "return" and this code correctly fails to compile { r.index = 0; r.c = &this; return r; } @safe struct Range { int front() { return c.arr[index]; } bool empty() { return index >= c.arr.length; } void popFront() { index++; } size_t index; Container* c; } private: Range r; int[] arr; } private struct S { void takesContainer(ref Container c) @safe { this.r = c[]; } void print() @safe { import std.stdio:writeln; writeln(r); } Container.Range r; } void doStuff(ref S s) @safe { auto c = Container(20); s.takesContainer(c); } @safe unittest { S s; doStuff(s); s.print(); }
Comment #2
by bugzilla — 2016-06-19T02:14:54Z
It compiles and prints: [] for me with any combination of -dip25 or not.