assume, assert, enforce, @safe

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 1 00:01:48 PDT 2014


On Friday, 1 August 2014 at 06:53:17 UTC, Kagamin wrote:
> On Thursday, 31 July 2014 at 19:31:51 UTC, Jonathan M Davis 
> wrote:
>> The whole type is templated, so the assertions will be 
>> compiled in based on whether the user's code is compiled with 
>> -released or not.
>
> Sounds tricky. Doesn't the compiler optimize template 
> instantiation? If it finds an already compiled template 
> instance somewhere, it will use it instead of generating new 
> one.

Since all template instantiations must happen when you compile 
your program rather than in any libraries you're linking against, 
why would it matter? If you compile your program without 
-release, then all assertions in all templates that your program 
uses will be enabled. The only cases where it wouldn't be would 
be when a library that you're linking against uses that template 
internally, but then it's that library's code and not yours, so 
it's probably out of your hands to deal with assertion failures 
in it anyway. Any template reuse that occurred would be reuse 
within your program and thus use the same flags. The only way 
that I can think of that that could be screwed up is if you're 
compiling each module separately and use different flags for 
each, but then each module which was compiled with -release 
wouldn't have assertions and those that weren't would. The 
compiler would never try to share any template instantiations 
across them. They wouldn't even be involved with each other until 
the linker was run on them, so the compiler wouldn't even have 
the chance to try and share anything between them.

- Jonathan M Davis


More information about the Digitalmars-d mailing list