[Issue 11394] NRVO should work for object field initialization in constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 1 09:05:55 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11394



--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2013-11-01 09:05:53 PDT ---
Sorry the OP code is incorrect, because the make function cannot have strong
purity.

Correct test case is:

debug = NRVO;
debug(NRVO) static void* pa, pb, pc;
static int[3] make(in int x) pure
{
    typeof(return) a;
    a[0] = x;
    a[1] = x + 1;
    a[2] = x + 2;
    debug(NRVO) pa = cast(void*)a.ptr;
    return a;
}
struct Bar
{
    immutable int[3] arr;

    this(int x)
    {
        this.arr = make(x);    // NRVO should work
        debug(NRVO) pb = cast(void*)this.arr.ptr;
    }
}
void main()
{
    auto b = Bar(5);
    debug(NRVO) pc = cast(void*)b.arr.ptr;
    debug(NRVO) assert(pa == pb);
    debug(NRVO) assert(pb == pc);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list