[Issue 19763] Cannot construct immutable struct from pure mutable struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 26 12:47:37 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19763

--- Comment #2 from ag0aep6g <ag0aep6g at gmail.com> ---
(In reply to ag0aep6g from comment #1)
> (In reply to Jacob Carlborg from comment #0)
[...]
> > Foo newFoo() pure
> > {
> >     return Foo(null);
> > }
[...]
> 
> This is ok, because newFoo [...] immediately returns the
> constructed Foo.

Correction: That doesn't matter. newFoo returns a mutable Foo, so it could
create the Foo, modify the data, and only then return the Foo. The important
bit is that the data is guaranteed to be newly created inside newFoo. It can't
come from a global or parameter. Any mutable references cease to exist when
newFoo returns.

--


More information about the Digitalmars-d-bugs mailing list