www.digitalmars.com         C & C++   DMDScript  

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?)

reply d-bugmail puremagic.com writes:
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=997


thomas-dloop kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Windows                     |All





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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=997


braddr puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |regression




-- 
Apr 13 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=997


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed DMD 1.013


-- 
Apr 20 2007