Comment #0 by simon.buerger — 2014-02-16T03:53:04Z
In the following code, no return value optimization is performed because foo contains multiple return statements. But it would be valid to do so, i.e. bitcopy the appropriate value into the return value of foo without calling the postblit (and destructor).
In C++, such optimization would be invalid in general. But in D, the struct is guaranteed not to contain pointers to itself. Therefore structs can be moved without destructor/postblit.
struct S
{
this(this) { writefln("copy"); }
}
S foo(bool x)
{
S a, b;
if(x) return a;
else return b;
}
void main() { foo(true); }
Comment #1 by robert.schadek — 2024-12-13T18:16:53Z