assert(0) behavior
Dicebot via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 3 08:57:33 PDT 2015
On Monday, 3 August 2015 at 15:50:56 UTC, Steven Schveighoffer
wrote:
> On 8/3/15 11:18 AM, Dicebot wrote:
>> On Monday, 3 August 2015 at 14:34:52 UTC, Steven Schveighoffer
>> wrote:
>>> Why do we do this?
>>
>> Because all asserts must be completely removed in -release
>
> 1. They aren't removed, they are replaced with a nearly useless
> segfault.
> 2. If we are going to put something in there instead of
> "assert", why not just throw an error?
>
> Effectively:
>
> assert(0, msg)
>
> becomes a fancy way of writing (in any mode, release or
> otherwise):
>
> throw new AssertError(msg);
>
> This is actually the way I thought it was done.
>
> -Steve
Now, they are completely removed. There is effectively no
AssertError present in -release (it is defined but compiler is
free to assume it never happens). I'd expect any reasonable
compiler to not even emit stack unwinding code for functions with
assert(0) (and no other throwables are present).
assert(0) is effectively same as gcc __builtin_unreachable with
all consequences for optimization - with only difference that
latter won't even insert HLT but just continue executing
corrupted program.
More information about the Digitalmars-d
mailing list