Automatic invariant generation

Nicholas Wilson via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 7 07:08:27 PDT 2017


On Friday, 7 July 2017 at 13:34:20 UTC, Steven Schveighoffer 
wrote:
> On 7/7/17 4:21 AM, Nicholas Wilson wrote:
>> The compiler seems to inset an `assert(this !is null, "null 
>> this");` into my struct.
>> which is for all intents and purposes.
>> struct Foo {
>>      Bar b;
>> }
>> 
>> struct Bar {
>>      void* ptr;
>> }
>
> What? When is this invariant called? I've never heard of a 
> hidden invariant being added to structs, structs are supposed 
> to be free of such things.
>
> I would call such a thing a bug.
>
> -Steve

I am missing a couple of methods on Foo in that example that in 
turn call the invariant.
That at least can be disable with -release, which while certainly 
not desirable is not a blocker _for me at the moment_. It is 
certainly unacceptable in the long run to demand that if users 
wish to use DCompute that they can't have asserts _in the code 
running in the host_.

However at the moment I'm have more trouble with 
https://forum.dlang.org/thread/ayanaomqklqvknzrljid@forum.dlang.org any help appreciated.


More information about the Digitalmars-d mailing list