proposed @noreturn attribute

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 8 21:40:38 PDT 2017


On 07/08/2017 05:03 PM, Vladimir Panteleev wrote:
> On Saturday, 8 July 2017 at 12:17:57 UTC, Andrei Alexandrescu wrote:
>>     @disable @property None init();
> 
> You meant static here I guess.
> 
>> 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.
> 
> Cheat: https://is.gd/pf25nP
> 
> Works because of NRVO I guess. This particular one is countered by also 
> adding a disabled destructor.

Eh, interesting. Indeed this doesn't compile anymore:

struct None
{
     @disable this();
     @disable this(this);
	@disable ~this();
     @disable static @property None init();
}

None fun()
{
	None none = void;
	return none;
}

void main()
{
     fun();
}

The type None would then go in object.d.

The compiler detects the pattern and make None implicitly convertible to 
anything so people can write things like:

int x = y ? 100 / y : fun();

Without the conversion, None is a less useful artifact.


Andrei


More information about the Digitalmars-d mailing list