Validity of cast(void*)size_t.max

Nordlöw per.nordlow at gmail.com
Mon Mar 5 11:41:35 UTC 2018


On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven 
Schveighoffer wrote:
> auto x = cast(Object)((cast(size_t *)null) + 1);

Thanks, how do I store it as enum or static immutable struct 
member?

In

@trusted pure unittest
{
     class C { int value; }
     C x;
     C y = cast(C)((cast(size_t*)null) + 1); // indicates a lazily 
deleted key
     struct S
     {
         enum C hole1 = cast(C)((cast(size_t*)null) + 1); // TODO 
make work
         static immutable C hole2 = cast(C)((cast(size_t*)null) + 
1); // TODO make work
     }
}

both `enum` and static` immutable` member declarations fail to 
compile with the same errors:

Error: cannot perform pointer arithmetic on non-arrays at compile 
time
Error: cannot perform pointer arithmetic on non-arrays at compile 
time

My only possible solution so far is to return the expression from 
an inline member function which I guess cannot be optimized as 
good as comparing to a compile-time value.


More information about the Digitalmars-d-learn mailing list