Can we just have struct inheritence already?

Exil Exil at gmall.com
Fri Jun 14 05:43:36 UTC 2019


On Friday, 14 June 2019 at 01:22:35 UTC, Timon Gehr wrote:
> On 14.06.19 03:17, Exil wrote:
>> 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:
>>>>> On Thursday, 13 June 2019 at 20:55:34 UTC, Exil wrote:
>>>>>> This problem happens because you are used @trusted. If you 
>>>>>> used @safe you wouldn't be able to increment pointers and 
>>>>>> modify the values the way you did in @trusted.
>>>>>
>>>>> 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.
>>>
>>> Which one seems most plausible to you?
>> 
>> None of them. Code generation is incorrect for boolean values.
>> ...
>
> That's the second option above... And I already explained why 
> that answer is not satisfactory.

It's not limited to void initialization, so no... More accurately 
code generation is incorrect for bools.

>>>> It seems it doesn't do bounds checking for the index because 
>>>> it is a bool value and it is less than the static type. If 
>>>> you change the array to a ____dynamically allocated____ one, 
>>>> an assert is hit as expected.
>>>
>>> That's not expected, this is just the compiler not being as 
>>> smart as it could be given the available information.
>> 
>> A value is used that is out of bounds of the array, yes that 
>> assert is expected.
>
> The compiler is able to derive that it is not out of bounds...

Not for dynamic arrays, which is what we are talking about.


More information about the Digitalmars-d mailing list