You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DMD version: 2.063.2
Code: http://pastebin.com/sTLhnNdV
Output:
CTor A with 42
CTor A with 23
CTor A with 65
Value call with A::65
DTor A with 65
CTor A with 1337
Value call with A::1337
DTor A with 1337
Ref call with A::42
DTor A with 23
DTor A with 42
Disassembly: http://pastebin.com/5emmwqJc
Compilation flags: -release -O
Issue:
The first two value calls receive their arguments via move semantics, i.e. the argument is not copied but passed directly to the function.
This behavior is showed in the output (the postblit function is not called) but the disassembly shows that the struct is actually copied before the function call.
The text was updated successfully, but these errors were encountered:
import std.stdio;
struct A {
public:
uint id;
uint data[128];
this(uint id) {
this.id = id;
writeln("CTor A with ", id);
}
this(this) {
writeln("Postblit A with ", this.id);
}
~this() {
writeln("DTor A with ", this.id);
}
A opBinary(string op : "+")(ref const A a) {
A r = A(this.id + a.id);
r.data[] += a.data[];
return r;
}
}
void func(const A a) {
writeln("Value call with A::", a.id);
}
void func(ref const A a) {
writeln("Ref call with A::", a.id);
}
void main()
{
A a = A(42);
A b = A(23);
asm { int 3; }
func(a + b);
asm { int 3; }
func(A(1337));
func(a);
}
badlink reported this on 2013-09-20T05:08:41Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=11073
CC List
Description
The text was updated successfully, but these errors were encountered: