dmd/changelog/dmd.unsafe-boolean-values.dd
2025-02-14 08:23:16 +08:00

15 lines
801 B
Text

For type `bool`, values other than 0 or 1 are not `@safe`
The spec [was updated](https://dlang.org/spec/type.html#bool)
(for 2.109) so that only 0 and 1 are
[safe values](https://dlang.org/spec/function.html#safe-values)
for `bool`. This means that reading a `bool` value whose underlying byte representation
has other bits set is implementation-defined and should be avoided.
Consequently the following are deprecated in `@safe` code:
* initialization of `bool` variables with `= void` (since 2.109)
* Reading a `bool` field from a union (since 2.109)
* Runtime casting a dynamic array to a `bool` dynamic array type
* Runtime casting a `bool` dynamic array to a tail mutable dynamic array type
* Casting a pointer to a `bool` pointer type
* Casting a `bool` pointer to a tail mutable pointer type