[Issue 20712] New: Struct construction/assignment in static constructors is broken
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 31 08:49:31 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20712
Issue ID: 20712
Summary: Struct construction/assignment in static constructors
is broken
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: maxsamukha at gmail.com
import std.stdio;
struct S {
this(int x) {
writeln("ctor");
}
ref S opAssign(ref const S s) {
writeln("assign");
return this;
}
~this() {
writeln("dtor");
}
}
S s;
static this() {
s = S(1); // (a)
s = S(1); // (b)
auto s2 = S(1);
s = s2; // (c)
}
void main()
{
}
(a) Constructor is correctly called on the "branded" struct.
(b) Bug: s is "branded" and constructed again. The original value doesn't get
destructed. A correct behavior would be to try opAssign and fail because of the
rvalue-to-ref mismatch.
(c) Bug: s2 is simply blitted to s. A correct behavior would be to call
opAssign.
--
More information about the Digitalmars-d-bugs
mailing list