https://issues.dlang.org/show_bug.cgi?id=20006
Walter Bright <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED Resolution|--- |INVALID --- Comment #3 from Walter Bright <[email protected]> --- Let's rewrite the example as: ---- struct Inserter { int* i; } ref Inserter ctor(return scope ref int) @safe; Inserter func() @safe { int i; return ctor(i); } --- because, as I endlessly point out, in order to understand what is going on, REWRITE IN SIMPLE TERMS. I.e. lower like the compiler does. In this case, get rid of auto, get rid of member functions, etc. Note constructors return by ref. The reason no error is given is because ctor() is told to attach the address of i to ctor()'s return value, which is a reference to an instance of Inserter. Now, because Inserter is returned by value, not by reference, the referred to value is returned, NOT THE REFERENCE! Only the ref is protected, not the value being referenced. Not a bug. I know this is complicated, and the ONLY way to understand it is to peel away the complexity by lowering it to ref's and pointer's and nothing else. --
