@safe accessing of union members

ag0aep6g anonymous at example.com
Wed Mar 17 19:09:18 UTC 2021


On Wednesday, 17 March 2021 at 18:01:43 UTC, Paul Backus wrote:
> On Wednesday, 17 March 2021 at 16:43:25 UTC, Q. Schroll wrote:
[...]
>> When should the language (conservatively) assume an aggregate 
>> type (struct, class, etc.) has invariants?
>
> The rules in the language spec [2] are mostly correct in this 
> regard, though they leave out `bool` (and enum types, though 
> that's a more debatable issue).
[...]
> [2] https://dlang.org/spec/function.html#safe-values

I left out bool deliberately. The impression I get from Walter is 
that he only considers indirections to be potentially unsafe [1]. 
In anticipate him addressing issue by defining 0 = false, 
anything else = true. Then all bit patterns are safe, and it's 
just a matter of fixing code that expects only 0 or 1.


[1] https://github.com/dlang/dlang.org/pull/2260


More information about the Digitalmars-d mailing list