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.
Comment #1 by razvan.nitu1305 — 2018-04-12T14:32:14Z
dlang/dmd pull request #10139 "Fix Issue 18719 - Doubly-called constructor against member when using forwarding constructors: Deprecation -> Error" was merged into master:
- 97808a239d0f531863ca5c8e174a0232c828347e by Mike:
Fix Issue 18719 - Doubly-called constructor against member when using forwarding constructors: Deprecation -> Error
https://github.com/dlang/dmd/pull/10139
Comment #4 by dlang-bot — 2021-01-25T11:18:39Z
dlang/dmd pull request #12153 "[dmd-cxx] Backport fixes for issue 18143 and 18719." was merged into dmd-cxx:
- 0bfc9948b40afacda1c91a50fda2b6176d6b26de by RazvanN7:
[dmd-cxx] Fix Issue 18719 - Doubly-called constructor against member when using forwarding constructors
https://github.com/dlang/dmd/pull/12153