https://issues.dlang.org/show_bug.cgi?id=23164
Iain Buclaw <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #5 from Iain Buclaw <[email protected]> --- (In reply to Mathias LANG from comment #0) > The following code shows 2 assertions failures in v2.096.1, an infinite loop > on v2.097.0: > ``` --snip-- > ~this () > { > assert(this.ptr is &this); > } --snip-- > ``` > > The original test was to see whether or not DMD would move a struct with a > copy constructor. The above code compiles and runs fine with LDC & GDC, but > asserts with DMD. To explain GDC behaviour. *Because* there is a destructor (or postblit, copy constructor, or anything that would other make the struct non-trivially copyable) then the type is *always* *implicitly* passed and returned by invisible reference. The right reduction would be this: ``` struct std_string { std_string* ptr; ulong[3] data; this (ulong data) { this.data[] = data; this.ptr = &this; } ~this () { } // GDC and LDC forces 'auto ref' to be 'ref', even when the // front-end decides to drop the 'ref' from the signature. ref std_string opAssign()(const auto ref std_string rhs) { assert(rhs.ptr is &rhs); return this; } } void main () { std_string tmp; tmp = std_string(42); } ``` --
