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

Moritz Maxeiner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 27 05:52:27 PDT 2017


On Sunday, 27 August 2017 at 10:46:53 UTC, Andrew Chapman wrote:
> [...]
>
> Oh interesting.  Does DUB support passing through the 
> --enable-contracts flag to ldc?  Also, if this is an ldc 
> specific thing it's probably not a good idea i'd imagine, since 
> in the future one may want to use a GDC, or DMD?

Also, with regards to gdc, its release mode `-frelease` option is 
explicitly specified in the manual as being shorthand for a 
specific set of options:

>> This is equivalent to compiling with the following options:
>>
>> gdc -fno-assert -fbounds-check=safe -fno-invariants \
>>     -fno-postconditions -fno-preconditions -fno-switch-errors

As it doesn't seem to turn on/off any other options / 
optimizations, you can use `"dflags-gdc": [...]` to specify your 
own set of "release" options without losing anything.
In particular, I would overwrite dub's default "release" build 
type [1] and add your own per compiler build settings, so dub 
won't pass `-frelease` to gdc when using `dub --build=release`.

[1] https://code.dlang.org/package-format?lang=json#build-types


More information about the Digitalmars-d-learn mailing list