Bug 18719 – Doubly-called constructor against member when using forwarding constructors

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-04-03T21:15:29Z
Last change time
2021-01-25T11:18:39Z
Keywords
safe
Assigned to
No Owner
Creator
Andrei Alexandrescu
See also
https://issues.dlang.org/show_bug.cgi?id=19030

Comments

Comment #0 by andrei — 2018-04-03T21:15:29Z
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
Comment #2 by github-bugzilla — 2018-04-16T15:45:39Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/cbb49cb2591bd5aa3e5f9e0b8a4350cb04ec1206 Fix Issue 18719 - Doubly-called constructor against member when using forwarding constructors https://github.com/dlang/dmd/commit/ebecaf95ec84018c36cd1c388c4d9102c23622f7 Merge pull request #8167 from RazvanN7/Issue_18719 Fix Issue 18719 - Doubly-called constructor against member when using forwarding constructors merged-on-behalf-of: Andrei Alexandrescu <[email protected]>
Comment #3 by dlang-bot — 2019-07-05T09:31:50Z
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