proposed @noreturn attribute
Stefan Koch via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jul 8 05:20:55 PDT 2017
On Saturday, 8 July 2017 at 12:17:57 UTC, Andrei Alexandrescu
wrote:
> On 7/8/17 6:15 AM, Walter Bright wrote:
>> Has anyone a better idea? Does anyone want to write a DIP for
>> this?
>
> An attribute is fine. A more PL-minded possibility is to return
> a specific type:
>
> struct None
> {
> @disable this();
> @disable this(this);
> @disable @property None init();
> }
>
> None ThisFunctionExits();
>
> The compiler detects (without having anything hardwired about
> the particular type "None") that the type None is impossible to
> create and copy/move from a function, and therefore decrees the
> function will never return.
>
>
> Andrei
... since it's going to be special cased by the compiler we might
as well hardwire a type called none.
Although it seems to be that the scope of no-return is extremely
narrow.
Because we do have precisely builtin assert(0).
More information about the Digitalmars-d
mailing list