[Issue 11343] [2.064 beta] Error: multiple field initialization
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 30 02:43:29 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11343
--- Comment #13 from bearophile_hugs at eml.cc 2013-10-30 02:43:17 PDT ---
(In reply to comment #8)
> this(int x) {
> static int[3] make(int x) pure {
> int[3] a;
> a[0] = x;
> a[1] = x + 1;
> a[2] = x + 2;
> }
> this.arr = make(x); // NRVO works
> }
A little test program:
struct Foo {
int[3] arr;
this(int x) pure nothrow {
arr[0] = x;
arr[1] = x + 1;
arr[2] = x + 2;
}
}
struct Bar {
immutable int[3] arr;
this(int x) pure nothrow {
static int[3] make(in int x) pure nothrow {
typeof(return) a;
a[0] = x;
a[1] = x + 1;
a[2] = x + 2;
return a;
}
this.arr = make(x); // NRVO works
}
}
void main() {
auto f = Foo(5);
auto b = Bar(5);
}
The asm of its struct constructors using dmd:
dmd -O -release -inline -noboundscheck test.d
Foo.__ctor:
push EBX
mov EDX, EAX
mov EBX, 8[ESP]
push ESI
lea ECX, 1[EBX]
lea ESI, 2[EBX]
mov [EDX], EBX
mov 4[EDX], ECX
mov 8[EDX], ESI
pop ESI
pop EBX
ret 4
Bar.__ctor:
sub ESP, 010h
xor EDX, EDX
push EBX
mov EBX, 018h[ESP]
push ESI
lea ESI, 1[EBX]
push EDI
lea EDI, 2[EBX]
mov 018h[ESP], EAX
push 0Ch
lea ECX, 010h[ESP]
mov [ECX], EDX
mov 4[ECX], EDX
mov 8[ECX], EDX
mov 010h[ESP], EBX
mov 014h[ESP], ESI
mov 018h[ESP], EDI
push ECX
push EAX
call near ptr _memcpy
add ESP, 0Ch
mov EAX, 018h[ESP]
pop EDI
pop ESI
pop EBX
add ESP, 010h
ret 4
--
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