Bug 21367 – Nameless union propagates copy constructors and destructors over all members

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-11-07T08:33:14Z
Last change time
2021-11-18T12:51:37Z
Keywords
pull
Assigned to
No Owner
Creator
Илья Ярошенко

Comments

Comment #0 by ilyayaroshenko — 2020-11-07T08:33:14Z
This is a very old regression. struct RCArray(T) { T* data; this(this){pragma(inline, false);} ~this() { pragma(inline, false); } } struct Variant(T...) { union { T payload; } this(this){pragma(inline, false);} ~this() { pragma(inline, false); } } alias Ft = Variant!(RCArray!double, RCArray!int); The quite old compilers (DMD v2.068.2 or LDC 0.17.2) generates a proper error message ------- <source>(11): Error: struct example.Variant!(RCArray!double, RCArray!int).Variant destructors, postblits and invariants are not allowed in overlapping fields __payload_field_0 and __payload_field_1 <source>(24): Error: template instance example.Variant!(RCArray!double, RCArray!int) error instantiating Compiler returned: 1 Read the new cookie policy ------- While the newer compilers generate wrong code that tries to destroy and postblit all union members: pure nothrow @nogc @trusted void example.Variant!(example.RCArray!(double).RCArray, example.RCArray!(int).RCArray).Variant.__fieldDtor(): push rbp mov rbp, rsp sub rsp, 16 mov rax, rdi mov qword ptr [rbp - 8], rdi mov rdi, rax call pure nothrow @nogc @safe void example.RCArray!(int).RCArray.__dtor()@PLT mov rdi, qword ptr [rbp - 8] call pure nothrow @nogc @safe void example.RCArray!(double).RCArray.__dtor()@PLT add rsp, 16 pop rbp ret pure nothrow @nogc @safe void example.Variant!(example.RCArray!(double).RCArray, example.RCArray!(int).RCArray).Variant.__aggrDtor(): push rbp mov rbp, rsp sub rsp, 16 mov qword ptr [rbp - 8], rdi call pure nothrow @nogc @safe void example.Variant!(example.RCArray!(double).RCArray, example.RCArray!(int).RCArray).Variant.__dtor()@PLT mov rdi, qword ptr [rbp - 8] call pure nothrow @nogc @trusted void example.Variant!(example.RCArray!(double).RCArray, example.RCArray!(int).RCArray).Variant.__fieldDtor()@PLT add rsp, 16 pop rbp ret
Comment #1 by dlang-bot — 2021-11-17T12:32:08Z
@RazvanN7 created dlang/dmd pull request #13315 "Fix Issue 21367 - Nameless union propagates copy constructors and destructors over all members" fixing this issue: - Fix Issue 21367 - Nameless union propagates copy constructors and destructors over all members https://github.com/dlang/dmd/pull/13315
Comment #2 by dlang-bot — 2021-11-18T12:51:37Z
dlang/dmd pull request #13315 "Fix Issue 21367 - Nameless union propagates copy constructors and destructors over all members" was merged into master: - acbcb63c450e3f69b84f1bdeaf02b86eb24ce615 by RazvanN7: Fix Issue 21367 - Nameless union propagates copy constructors and destructors over all members https://github.com/dlang/dmd/pull/13315