assume, assert, enforce, @safe

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 08:48:41 PDT 2014


On Thursday, 31 July 2014 at 07:42:16 UTC, Walter Bright wrote:
> On 7/30/2014 6:16 PM, Dicebot wrote:
>> On Wednesday, 30 July 2014 at 23:50:51 UTC, H. S. Teoh via 
>> Digitalmars-d wrote:
>>> But if you don't want to check ever to be removed, currently 
>>> you have to
>>> write:
>>>
>>>    if (!requiredCondition)
>>>        assert(0); // compiler never removes this
>>>
>>> which IMO is relatively clear, and the use of assert(0) for 
>>> forceful
>>> termination is consistent with existing practice in D code.
>>
>> Not helping.
>>
>> ```
>> import std.stdio;
>>
>> void foo()
>> in { writeln("in contract"); }
>> body { }
>>
>> void main() { foo(); }
>> ```
>>
>> Compile with -release and check the output.
>
> What do you expect to happen?

It acts as defined in spec, nothing unexpected here. I was 
referring to H. S. Teoh proposed workaround to keep assertions in 
release mode - it does not work with contracts because those are 
eliminated completely, not just assertions inside.


More information about the Digitalmars-d mailing list