digitalmars.D.bugs - [Issue 11394] New: NRVO should work for object field initialization in constructor
- d-bugmail puremagic.com (50/50) Oct 30 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11394
- d-bugmail puremagic.com (35/35) Nov 01 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11394
- d-bugmail puremagic.com (10/10) Nov 01 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11394
http://d.puremagic.com/issues/show_bug.cgi?id=11394 Summary: NRVO should work for object field initialization in constructor Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: k.hara.pg gmail.com Spin-off issue from http://d.puremagic.com/issues/show_bug.cgi?id=11343#c15 At the line 18, NRVO should work, then p1, p2, p3 should print same address. extern(C) int printf(const char*, ...); static int[3] make(in int x, out const(int)* p) pure { typeof(return) a; a[0] = x; a[1] = x + 1; a[2] = x + 2; p = a.ptr; return a; } struct Bar { immutable int[3] arr; this(int x, out const(int)* p2) { const(int)* p1; this.arr = make(x, p1); // Line 18: NRVO should work p2 = this.arr.ptr; printf("p1 = %p\np2 = %p\n", p1, p2); //assert(p1 == p2); } } void main() { const(int)* p2; auto b = Bar(5, p2); const(int)* p3 = b.arr.ptr; printf("p3 = %p\n", p3); //assert(p2 == p3); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 30 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11394 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: -------
Nov 01 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11394 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull https://github.com/D-Programming-Language/dmd/pull/2592 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 01 2013