why static array can be reassigned with new allocation?

Timon Gehr timon.gehr at gmx.ch
Sat Oct 15 12:45:45 UTC 2022


On 15.10.22 14:10, Tejas wrote:
> On Saturday, 15 October 2022 at 11:29:00 UTC, rassoc wrote:
>> On 10/14/22 21:46, jfondren via Digitalmars-d wrote:
>>> and it crashes with an oversized array as the lengths don't match
>>
>> Try compiling with -release for extra fun, or not.
> 
> It printed the arrays
>   ```
> [0, 0, 0]
> [0, 0, 0]
> ```
> ... lol did it cache the results of the previous call? Somebody please 
> explain this, is this what Timon meant by undefined behaviour getting 
> introduced in programs whose `assert`s get removed from the code?

The code has UB with -release, but it is a different case. There are no 
asserts in it. Currently, failing asserts introduce UB in -release even 
if they are not guarding against anything that would ordinarily cause 
UB. I think that's not justifiable.


More information about the Digitalmars-d mailing list