[Issue 18719] New: Doubly-called constructor against member when using forwarding constructors
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Apr 3 21:15:29 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18719
Issue ID: 18719
Summary: Doubly-called constructor against member when using
forwarding constructors
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: andrei at erdani.com
Consider:
struct S
{
int x = -1;
this(int y) immutable
{
x = y;
import std.stdio;
writeln("Ctor called with ", y);
}
void opAssign(int) immutable;
}
class C
{
S x;
this() immutable
{
this(42); /* Initializes x. */
x = 13; /* Breaking immutable, or ok? */
}
this(int x) immutable
{
this.x = x;
}
}
void main()
{
new immutable C;
}
The code prints:
Ctor called with 42
Ctor called with 13
Constructor should not be called twice against the same object.
--
More information about the Digitalmars-d-bugs
mailing list