proposed @noreturn attribute

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 16 05:41:06 PDT 2017


On 16.07.2017 05:30, Walter Bright wrote:
> On 7/13/2017 5:18 PM, Andrei Alexandrescu wrote:
>> On 7/13/17 2:37 PM, Timon Gehr wrote:
>>> On Thursday, 13 July 2017 at 17:25:18 UTC, Timon Gehr wrote:
>>>> Anyway, my assertion that Bottom cannot be a subtype of all other 
>>>> types was actually incorrect: the compiler does not need to generate 
>>>> code for implicit conversion from Bottom to some other type, so it 
>>>> can be treated as a subtype.
>>>> ...
>>>
>>> (Actually, there are some complications like the .sizeof property. 
>>> Anyway, it is clear what the semantics of Bottom are, no matter 
>>> whether it is subtyping or implicit conversion.)
>>
>> I wonder if sizeof could be made size_t.max. -- Andrei
> 
> I thought bottom.sizeof would be 0.

0 is the obvious size for the unit type (the type with a single value, 
in D this is for example void[0]), as in:

struct S{
     T x;
     void[0] nothing;
}
static assert(S.sizeof == T.sizeof);

on the other hand

struct S{
    T x;
    Bottom everything;
}

turns the entire struct into an empty type. It is therefore most natural 
to say that Bottom.sizeof == ∞. (It's the only choice for which S.sizeof 
== Bottom.sizeof.)

Another way to think about it: If something of type A* converts to 
something of type B* without problems, then one would expect B.sizeof <= 
A.sizeof. This would imply that Bottom.sizeof >= size_t.max. (Because 
Bottom* converts to all other pointer types.)

One small issue is that one needs to avoid overflow for the size of a 
struct that has multiple fields where one of them is of type Bottom.



More information about the Digitalmars-d mailing list