[Issue 15848] New: out doesn't call opAssign()
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Mar 29 07:52:29 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15848
Issue ID: 15848
Summary: out doesn't call opAssign()
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: schuetzm at gmx.net
import std.stdio;
void foo(out Test x) {
writeln("x.n = ", x.n);
}
struct Test {
int n;
~this() {
writeln("~this()");
}
int opAssign(int val) {
writefln("opAssign(%s)", val);
return n = val + 1;
}
}
void main() {
Test t;
foo(t);
writeln("done");
}
// output:
x.n = 0
done
~this()
Conclusion:
Upon entering foo(), Test.opAssign() is not called. An argument could be made
that `out` shouldn't construct a new struct, not assign an existing one, but in
that case, it would have to call Test.~this(), which doesn't happen either.
--
More information about the Digitalmars-d-bugs
mailing list