digitalmars.D.bugs - [Issue 997] New: [Regression] Struct-returning function that conditionally passes the result of another function straight through doesn't work (NRVO bug?)
- d-bugmail puremagic.com (58/58) Feb 22 2007 http://d.puremagic.com/issues/show_bug.cgi?id=997
- d-bugmail puremagic.com (13/13) Feb 26 2007 http://d.puremagic.com/issues/show_bug.cgi?id=997
- d-bugmail puremagic.com (6/6) Apr 13 2007 http://d.puremagic.com/issues/show_bug.cgi?id=997
- d-bugmail puremagic.com (9/9) Apr 20 2007 http://d.puremagic.com/issues/show_bug.cgi?id=997
http://d.puremagic.com/issues/show_bug.cgi?id=997 Summary: [Regression] Struct-returning function that conditionally passes the result of another function straight through doesn't work (NRVO bug?) Product: D Version: 1.007 Platform: PC OS/Version: Windows Status: NEW Keywords: wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: smjg iname.com I found this when one of my programs had stopped working. Clearly there is work to be done to get NRVO behaving itself. ---------- import std.stdio, std.string; struct Rect { int left, top, right, bottom; } int main() { print(sizeTest(false)); print(sizeTest(true)); print(defaultRect); return 0; } static Rect sizeTest(bool empty) { if (empty) { Rect result; return result; //return Rect.init; } else { return defaultRect; /+Rect result = defaultRect; return result;+/ } } void print(Rect r) { writefln("(%d, %d)-(%d, %d)", r.left, r.top, r.right, r.bottom); } Rect defaultRect() { return Rect.init; } ---------- (1, 4212215)-(0, 4291676) (0, 0)-(0, 0) (0, 0)-(0, 0) ---------- If I remove the if, or use either of the commented out portions instead, then I get the expected output: ---------- (0, 0)-(0, 0) (0, 0)-(0, 0) (0, 0)-(0, 0) ---------- --
Feb 22 2007
http://d.puremagic.com/issues/show_bug.cgi?id=997 thomas-dloop kuehne.cn changed: What |Removed |Added ---------------------------------------------------------------------------- OS/Version|Windows |All ------- Comment #1 from thomas-dloop kuehne.cn 2007-02-26 05:37 ------- Added to DStress as http://dstress.kuehne.cn/run/s/struct_28_A.d http://dstress.kuehne.cn/run/s/struct_28_B.d http://dstress.kuehne.cn/run/s/struct_28_C.d http://dstress.kuehne.cn/run/s/struct_28_D.d http://dstress.kuehne.cn/run/s/struct_28_E.d --
Feb 26 2007
http://d.puremagic.com/issues/show_bug.cgi?id=997 braddr puremagic.com changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |regression --
Apr 13 2007
http://d.puremagic.com/issues/show_bug.cgi?id=997 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #2 from bugzilla digitalmars.com 2007-04-20 13:17 ------- Fixed DMD 1.013 --
Apr 20 2007