Automatic invariant generation

Nicholas Wilson via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 9 04:45:42 PDT 2017


On Sunday, 9 July 2017 at 11:37:55 UTC, Steven Schveighoffer 
wrote:
> On 7/9/17 7:00 AM, Walter Bright wrote:
>> On 7/9/2017 3:37 AM, Steven Schveighoffer wrote:
>
>>> Yet, here is an example of where we have effectively added a 
>>> null pointer exception. > At the very least, this should be 
>>> eliminated on Linux
>>> and just use the signal handling null pointer error mechanism!
>> 
>> You're a few years late, as pretty much nobody agreed with me 
>> that the operating system handling of it was plenty.
>
> I think you misunderstand, we have etc.linux.memoryerror that 
> can actually throw an error on a null pointer using the signal 
> handler.
>
> I have a suggestion: eliminate this feature, and add a -npe 
> switch to the compiler that errors on any null pointer usage. 
> Asserts will be sprinkled in everywhere, but may be useful to 
> someone debugging a nasty null pointer segfault somewhere.
>
> -Steve

I think the generated assert(this !is null) has its place, it is 
useful to catch a null this as early as possible but not by 
default. Perhaps debug mode (as in the compiler switch) or a 
switch of its own.


More information about the Digitalmars-d mailing list