[OT] OT: Null checks.

Timon Gehr timon.gehr at gmx.ch
Tue May 6 23:59:53 UTC 2025


On 5/7/25 01:28, Walter Bright wrote:
> On 5/5/2025 8:31 PM, Timon Gehr wrote:
>> I am perfectly content with it throwing an assert error and unwinding 
>> the stack. This is just not what druntime will do in the default build 
>> that ships with the compiler.
> 
> If you add the -checkaction=D after the -release switch, then the assert 
> will throw an Error. (Putting it after means it overrides the previous 
> setting made by the -release)
> ...

I would never use `-release` in production for this project, but still 
note that what you say does not work:


```d
module test;
import std.stdio;

void main(){
     int[2] x=[0,1];
     auto y=x[1..2];
     x[]=y[];
     writeln(x," ",y);
}
```

```
$ ./ldc2-1.41.0-beta1-linux-x86_64/bin/ldmd2 -run test
Error: /tmp/test-5d6670 failed with status: -2
        message: Illegal instruction (core dumped)
Error: program received signal 2 (Interrupt)
```

This is something I don't want to see, ever.

It will however happen every time code triggers one of the `-release` 
`assert(0)` hidden in the druntimes that ship with DMD and LDC.


```
$ ./ldc2-1.41.0-beta1-linux-x86_64/bin/ldmd2 -release -checkaction=D 
-run test
[1, 21640336] [21640336]
```

This is even worse. Silent memory corruption. druntime and Phobos should 
get rid of `-release`.


> (Actually, it throws a `staticError!AssertError(msg, file, line)` which 
> is derived from `Error`.)
> 
> (I don't know why it has to go through all these layers and layers of 
> templates.)

I guess this is done so it does not use the GC. (Which answers my 
earlier question what to replace all the `assert(0)` spam with.)


More information about the Digitalmars-d mailing list