Bug 19180 – Expose dmd.mtype.Type.isZeroInit as __traits(isZeroInit, T)
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-08-20T01:38:15Z
Last change time
2021-01-03T22:57:19Z
Assigned to
No Owner
Creator
Nathan S.
Comments
Comment #0 by n8sh.secondary — 2018-08-20T01:38:15Z
It's useful to identify at compile time types with 0 initializers. Doing this with CTFE and templates is slow and memory-hungry[1] and runs into errors[2][3]. The compiler already has its own check for this that we can expose instead.
Proposed syntax is `__traits(isZeroInit, T)` where the second argument must resolve to the type T itself instead of being any expression whose result is an instance of T. This would be to prevent someone from mistakenly thinking he can use `__traits(isInitZero, x)` to test whether some variable `x` was explicitly initialized as zero.
[1] https://github.com/dlang/phobos/pull/6537
[2] https://github.com/dlang/phobos/pull/6670#issuecomment-414111649
[3] https://github.com/dlang/phobos/pull/6461
Comment #1 by n8sh.secondary — 2018-08-20T01:57:22Z
dlang/dmd pull request #12093 "[dmd-cxx] Backport more recent traits to the C++ port" was merged into dmd-cxx:
- c480509b0f455c8dc86c70752d55e517ca3d7416 by Nathan Sashihara:
[dmd-cxx] Fix Issue 19180 - Expose dmd.mtype.Type.isZeroInit as __traits(isZeroInit, T)
https://github.com/dlang/dmd/pull/12093