@noreturn?

Iain Buclaw ibuclaw at ubuntu.com
Mon May 14 06:37:33 PDT 2012


On 14 May 2012 13:21, Alex Rønne Petersen <xtzgzorex at gmail.com> wrote:
> On 14-05-2012 14:13, Alex Rønne Petersen wrote:
>>
>> On 14-05-2012 13:53, bearophile wrote:
>>>
>>> Alex Rønne Petersen:
>>>
>>>> In writing unwinding mechanisms for my VM, I find myself actually
>>>> needing some sort of @noreturn function attribute that would tell the
>>>> compiler that the function does not return,
>>>
>>>
>>> Maybe Walter will listen you more if you show an example of where/why
>>> you would use @noreturn.
>>>
>>> Bye,
>>> bearophile
>>
>>
>> As a very simple example, consider an intrinsic in a virtual machine:
>>
>> extern (C) int do_some_work(VMContext ctx, int value)
>> {
>> if (value != 42)
>> ctx.engine.raiseException("Bad value!");
>> /* no can do; assert(false) needed here */
>>
>> return value;
>> }
>>
>> Note that raiseException() unwinds the native stack. It is @noreturn.
>>
>
> Even more trivial examples... longjmp and abort. ;)
>
> --
> - Alex

Several of GDC's internal exception handing routines would benefit
greatly from not having assert(0) at the bottom of the function.


There are also a number of functions in druntime rt.lifetime that have
this at the end too.

...
    return XXX;

Loverflow:
    onOutOfMemoryError();
    assert(0);
}

If only onOutOfMemoryError() was markable as @noreturn. :^)


-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the Digitalmars-d mailing list