Bug 12180 – NRVO with multiple return statements

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-16T03:53:04Z
Last change time
2024-12-13T18:16:53Z
Assigned to
No Owner
Creator
Simon
Moved to GitHub: dmd#18773 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18773 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB