Just a friendly reminder about using arrays in boolean conditions
Steven Schveighoffer
schveiguy at gmail.com
Mon Nov 25 17:27:04 UTC 2024
On Saturday, 23 November 2024 at 00:57:01 UTC, kdevel wrote:
> On Sunday, 17 November 2024 at 22:17:18 UTC, Steven
> Schveighoffer wrote:
>> On Sunday, 17 November 2024 at 21:50:18 UTC, kdevel wrote:
>>> My question is: Is it possible that a valid D program gets
>>> into a
>>> state where an array has ptr == null and length > 0? If so,
>>> how?
>>
>> Yes, the compiler uses it:
>>
>> ```d
>> [...]
>> auto i = typeid(S).initializer;
>> [...]
>> ```
>
> Issue 20722 - typeid(X).initializer() breaks safety
> https://issues.dlang.org/show_bug.cgi?id=20722
Indeed, I don't think this should be considered safe. I don't
know how much code would break to change it to system.
But this is beside the point that I was trying to make -- that
this scenario does actually ahppen.
You can think of it as a storage of a pointer, which if null
means "all are zero", and a length, which is the number of bytes
in the initializer.
It is used in places where only TypeInfo is available. I believe
this is mostly for AA and array runtime, and nothing else.
Eventually we will be able to remove these dependencies.
-Steve
More information about the Digitalmars-d
mailing list