Confusion over enforce and assert - both are compiled out in release mode

Dukc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 27 03:35:52 PDT 2017


On Sunday, 27 August 2017 at 10:17:47 UTC, Andrew Chapman wrote:
> On Sunday, 27 August 2017 at 10:08:15 UTC, ag0aep6g wrote:
>> On 08/27/2017 12:02 PM, Andrew Chapman wrote:
>>> However, I am finding that BOTH enforce and assert are 
>>> compiled out by dmd and ldc in release mode.  Is there a 
>>> standard way of doing what enforce does inside an "in" 
>>> contract block that will work in release mode?
>>> 
>>> I'm guessing I should write my own function for now.
>> The whole `in` block is ignored in release mode. Doesn't 
>> matter what you put in there. Nothing of it will be compiled.
>
> Thanks, that explains it.  I think it's a bit of a shame that 
> the "in" blocks can't be used in release mode as the clarity 
> they provide for precondition logic is wonderful.

I actually think even better would be if they acted like array 
bounds checking -always there by default, in release mode done is 
@safe code but not in @system. And for none if bounds checking is 
disabled. That would let users implement custom bounds checking 
types. Asserts would still be always if in release version, 
bounds checking would be done by if ... throw.


More information about the Digitalmars-d-learn mailing list