D Language Foundation July 2023 Monthly Meeting Summary

Dukc ajieskola at gmail.com
Sun Aug 20 08:30:16 UTC 2023


On Friday, 11 August 2023 at 13:37:57 UTC, Mike Parker wrote:
> __void initialing Booleans__
>
> Dennis wasn't yet finished. The last item he had for us was [a 
> PR he had submitted](https://github.com/dlang/dmd/pull/15362) 
> that marks as `@system` the void initialization of a `bool`, or 
> anything that contains a Boolean, under the system variables 
> preview. The compiler likes to avoid bounds checks if you index 
> with a bool because it knows it can only be zero or one, but 
> when the bool is void initialized, it might be something bigger 
> than that and can corrupt memory. (The PR is attempting [to fix 
> an issue](https://issues.dlang.org/show_bug.cgi?id=20148) 
> brought up in [our Gripes & Wishes 
> campaign](https://github.com/dlang/vision-document/blob/main/gripes-wishes-feedback.md)).
>
> He said there were a few different opinions on what should 
> happen here. One is for every void initialization to be 
> `@system`, but that's a bigger breaking change that he doesn't 
> think is going to happen.

Would not be recommended anyway. It'd mean any union with `bool` 
would have to be `@system`.

> It might be helpful to consider `bool` a type that has unsafe 
> bit patterns. Walter said he would have to think about it, and 
> thanked Dennis for bringing it up.

I think `bool` other than 0 or 1 should be allowed, but have 
implementation defined behaviour:

```D
if(*cast(bool) new byte(2)) // implementation defined whether 
executed
// true or false, implementation defined
auto x = *cast(bool) new byte(2) && *cast(bool) new byte(2)
// true or false, implementation defined
auto y = *cast(bool) new byte(2) == *cast(bool) new byte(2)
// same as bool z = void
auto z = *cast(bool) new byte(2) & *cast(bool) new byte(2)
// not implementation defined anymore
z = true;
```

This unfortunately means that dmd has to stop assuming bool bit 
pattern of bool.


More information about the Digitalmars-d-announce mailing list