← Back to index
|
Original Bugzilla link
Bug 22635 – opCast prevent calling destructor for const this.
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-29T08:28:09Z
Last change time
2022-04-17T10:02:43Z
Keywords
pull
Assigned to
No Owner
Creator
vitamin
Comments
Comment #0
by submada — 2021-12-29T08:28:09Z
This code doesn't compile: ```d struct Foo{ bool opCast(T : bool)()const{ assert(0); } ~this(){} } struct Bar{ const Foo foo; } void main(){ } ``` Error: template instance `opCast!(Foo)` does not match template declaration `opCast(T : bool)()` Generated constructor Bar.~dtor is using Foo.opCast to remove const from foo before calling Foo.~this. Right way is to take address of foo and cast pointer without involvement of Foo.opCast. This bug prevent emplacing qualified struct with opCast + ~this(). Example: ```d struct Foo{ bool opCast(T : bool)()const{ assert(0); } this(int i){} ~this(){} } void main(){ import core.lifetime : emplace; void[Foo.sizeof] buffer = void; emplace(cast(const Foo*)&buffer, 42); } ``` Error: template instance `opCast!(Foo)` does not match template declaration `opCast(T : bool)()`
Comment #1
by dkorpel — 2022-03-31T14:06:02Z
Looks like this bug was introduced here:
https://github.com/dlang/dmd//commit/c9ff5810a2f449f19a39172461d511c895dcb519#diff-c76bae6626df560ca3a9196fbb5213427697c512191b729ece94da2d4e8ca568R1048
Comment #2
by dlang-bot — 2022-04-17T08:48:19Z
@dkorpel created dlang/dmd pull request #13999 "Fix issue 22635 - opCast prevent calling destructor for const this" fixing this issue: - Fix issue 22635 - opCast prevent calling destructor for const this
https://github.com/dlang/dmd/pull/13999
Comment #3
by dlang-bot — 2022-04-17T10:02:43Z
dlang/dmd pull request #13999 "Fix issue 22635 - opCast prevent calling destructor for const this" was merged into master: - aaaa9a1aec8ecc1d5753356a9811c80291f2a3c7 by Dennis Korpel: Fix issue 22635 - opCast prevent calling destructor for const this
https://github.com/dlang/dmd/pull/13999