Bug 23841 – isZeroInit does not take into account unions

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-04-15T17:22:48Z
Last change time
2024-10-05T16:40:11Z
Keywords
pull
Assigned to
No Owner
Creator
Dennis
See also
https://issues.dlang.org/show_bug.cgi?id=24776

Comments

Comment #0 by dkorpel — 2023-04-15T17:22:48Z
``` union U { float x = 0; float y; } static assert(__traits(isZeroInit, U)); // fails ``` It also wastes bytes in the binary because it emits `U.init` in .rodata instead of .bss. Workaround: add `=void` to void initialize the other union members.
Comment #1 by dlang-bot — 2024-09-20T16:16:13Z
@ntrel updated dlang/dmd pull request #16858 "Fix Bugzilla 24776 - Struct with anonymous union has wrong isZeroInit" fixing this issue: - Fix Bugzilla 23841 - isZeroInit does not take into account unions https://github.com/dlang/dmd/pull/16858
Comment #2 by dlang-bot — 2024-10-05T00:56:49Z
dlang/dmd pull request #16858 "Fix: isZeroInit does not take into account unions" was merged into master: - 261044eb866a952dab4063ea4aa945916bc444b1 by Nick Treleaven: Fix Bugzilla 23841 - isZeroInit does not take into account unions https://github.com/dlang/dmd/pull/16858