Bug 10372 – Document NRVO is applied in simple cases

Status
NEW
Severity
normal
Priority
P3
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-16T01:41:03Z
Last change time
2024-12-15T15:22:17Z
Keywords
spec
Assigned to
No Owner
Creator
Denis Shelomovskii
Depends on
10371
Moved to GitHub: dlang.org#4027 →

Comments

Comment #0 by verylonglogin.reg — 2013-06-16T01:41:03Z
If documentation will guarantee NRVO is applied in simple cases (i.e. no copy construction occurs) structs with disabled default construction will be able to be returned from functions (currently it is not guaranteed to compile): --- struct S { @disable this(this); } S makeS() { S s = S(); return s; } void main() { S s = makeS(); } --- Also Issue 10371 have to be fixed first.
Comment #1 by post — 2013-11-05T10:31:21Z
Even for cases where NRVO can't be applied, the spec should guarantee that the returned struct is moved and not copied. As far as I can tell, move-on-return can be applied whenever a struct is created on the stack and then returned. Here's an example of a case where NRVO can't necessarily be applied, but which should still compile: struct S { @disable this(this); } S makeS(bool b) { S s1; S s2; return b ? s1 : s2; } void main() { auto s = makeS(true); } Note that this compiles today, it just needs to be documented in the spec.
Comment #2 by verylonglogin.reg — 2013-11-05T11:49:44Z
(In reply to comment #1) > ... > auto s = makeS(true); Only `makeS` is related to this issue. This code is for Issue 10371.
Comment #3 by robert.schadek — 2024-12-15T15:22:17Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dlang.org/issues/4027 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB