Casting in Safe D

"Nordlöw" via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 27 00:10:31 PST 2014


On Thursday, 27 November 2014 at 00:27:59 UTC, David Held wrote:
> On 11/23/2014 3:12 PM, anonymous wrote:
>> [...]
>> And even pointer dereferencing is @safe. Invalid ones will fail
>> with a segfault at run time:
>> void foo(int* a) @safe {*a = 13;}
>
> Hmm...throwing an exception is a well-defined behavior, but is 
> segfaulting a well-defined behavior of correct D programs?  
> This seems like a peculiar definition of "safe" to me...
>
> Dave

I would personally see that this became a compile-time error in 
@safe code either always or even better when the compile cannot 
prove that the operation will never cause an exception at 
run-time.

Alternatively we could disallow this only in @safe *nothrow* 
functions.


More information about the Digitalmars-d-learn mailing list