proposed @noreturn attribute

Nicholas Wilson via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 9 04:38:39 PDT 2017


On Sunday, 9 July 2017 at 11:26:27 UTC, Steven Schveighoffer 
wrote:
> On 7/9/17 7:07 AM, Nicholas Wilson wrote:
>> On Sunday, 9 July 2017 at 10:59:43 UTC, Steven Schveighoffer 
>> wrote:
>>> On Sunday, 9 July 2017 at 10:51:50 UTC, Daniel N wrote:
>>>> On Sunday, 9 July 2017 at 10:31:47 UTC, Mr.D wrote:
>>>>> On Saturday, 8 July 2017 at 10:15:39 UTC, Walter Bright 
>>>>> wrote:
>>>>>
>>>>>> Has anyone a better idea?
>>>>>
>>>>> What about
>>>>>
>>>>> scope(exit) assert(0);
>>>>>
>>>>> ?
>>>>
>>>> void func()
>>>> out { assert(0); }
>>>> body
>>>> {
>>>> }
>>>
>>> Yes, this!
>>>
>> That certainly signals intention, but I still think that an 
>> attribute is a whole lot simpler than compiler voodoo like 
>> this or the "None" discussed earlier.
>
> This whole proposal is compiler voodoo :)
>
> Unlike a currently undefined attribute, assert(0) in the out 
> contract currently is effective to mean no return. It also 
> guarantees that if there is a return statement somewhere, it 
> still doesn't return.
>
> Also, since the out contract is part of the signature, it will 
> still be present in the case of separate compilation.
>
> The one disadvantage, is that -release removes contracts. So in 
> this particular case, the out contract should remain.
>
> Not sure if it has been mentioned yet, but @disable(return) 
> could work as something that doesn't add any new attributes.
>
> -Steve

If the compiler is like a magician, adding an attribute is like 
conjuring a rabbit, adding the "None" would be like summoning 
Chthulu.

I like the @disable(return) but I still think a plain attribute 
is the simplest way to achieve the goals of:
* documentation, is doesn't get much simpler than @noreturn
* optimisation, its already in LDC and GDC, just under a 
different name
* compatibility between compilers, its as simple as an alias in a 
version statement per compiler.



More information about the Digitalmars-d mailing list