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

Andrew Chapman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 27 03:02:38 PDT 2017


In the docs regarding contract programming and the use of enforce 
/ assert:
https://dlang.org/library/std/exception/enforce.html

it says:

"enforce is used to throw exceptions and is therefore intended to 
aid in error handling. It is not intended for verifying the logic 
of your program. That is what assert is for. Also, do not use 
enforce inside of contracts (i.e. inside of in and out blocks and 
invariants), because they will be compiled out when compiling 
with -release. Use assert in contracts."

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.


More information about the Digitalmars-d-learn mailing list