assume, assert, enforce, @safe

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 12:11:54 PDT 2014


On 07/31/2014 09:03 PM, Walter Bright wrote:
> On 7/31/2014 3:24 AM, ponce wrote:
>> On Thursday, 31 July 2014 at 09:13:53 UTC, Walter Bright wrote:
>>> On 7/31/2014 1:23 AM, Daniel Murphy wrote:
>>>> "Walter Bright"  wrote in message news:lrbpvj$mih$1 at digitalmars.com...
>>>>
>>>>> 5. assert(0); is equivalent to a halt, and the compiler won't
>>>>> remove it.
>>>>
>>>> This is not the same definition the spec gives.  The spec says
>>>> assert(0) can be
>>>> treated as unreachable, and the compiler is allowed to optimize
>>>> accordingly.
>>>
>>> It says more than that:
>>>
>>> "The expression assert(0) is a special case; it signifies that it is
>>> unreachable code. Either AssertError is thrown at runtime if it is
>>> reachable,
>>> or the execution is halted (on the x86 processor, a HLT instruction
>>> can be
>>> used to halt execution). The optimization and code generation phases of
>>> compilation may assume that it is unreachable code."
>>>
>>>   -- http://dlang.org/expression.html#AssertExpression
>>
>> You said "the compiler won't remove it".
>
> Right, and it doesn't.
>
>> http://dlang.org/expression.html#AssertExpression says: "The
>> optimization and
>> code generation phases of compilation may assume that it is
>> unreachable code."
>>
>> Who is right?
>
> It means if the control flow does actually get there, a HALT is executed.
>

And assuming control flow does not actually get there?


More information about the Digitalmars-d mailing list