Can we just have struct inheritence already?

XavierAP n3minis-git at yahoo.es
Sat Jun 15 08:40:52 UTC 2019


On Friday, 14 June 2019 at 01:12:21 UTC, Timon Gehr wrote:
> On 14.06.19 02:23, Exil wrote:
>> On Thursday, 13 June 2019 at 21:26:37 UTC, Tim wrote:
>>> Here is a completly @safe version:
>>>
>>> import std.stdio;
>>>
>>> static int[2] data;
>>> static int[253] data2;
>>>
>>> void test(bool b) @safe
>>> {
>>>     data[b]++;
>>> }
>>>
>>> void main() @safe
>>> {
>>>     bool b = void;
>>>     writeln(data, data2);
>>>     test(b);
>>>     writeln(data, data2);
>>> }
>>>
>>> If b is valid only data can change. But for me data2 changes, 
>>> even though it is never written to.
>> 
>> This is a bug.
>
> Yes. And the bug is either
> - that `void` initialization of `bool` is `@safe`.
> - that `void` initialization of `bool` can produce a value that 
> is both `true` and `false`.
> - that boolean values are assumed to be either `true` or 
> `false` in @safe code.

I'm not yet sure in the general case about void initialization, 
but for me this interesting case shows that:

- void initialization of bool should be illegal, not just in 
@safe code, anywhere. Initializing an int void works as 
(undefinedly) as intended, but with bool it breaks the spec;

- I never understood why D adopted over from C/C++ that bool is 
int and implicitly convertible; I don't understand when this may 
be useful.


More information about the Digitalmars-d mailing list