Challenge: write a reference counted slice that works as much as possible like a built-in slice

Paul Backus snarwin at gmail.com
Wed Dec 15 14:39:27 UTC 2021


On Wednesday, 15 December 2021 at 10:17:49 UTC, Walter Bright 
wrote:
> On 12/14/2021 6:05 AM, Paul Backus wrote:
>> If you can find a way to actually cause UB in @safe code, you 
>> should post it on the bug tracker. However, this example does 
>> not qualify.
>
> UB is not quite right. It's about memory unsafety. Another way 
> to illustrate this is:
>
>   import std.stdio;
>
>   @safe void main() {
>     int x = void;
>     writeln(x);
>   }
>
> will print garbage, but it is not unsafe.

A violation of memory unsafety is either (a) UB or (b) behavior 
that is not UB itself, but allows UB to occur in @safe code 
(i.e., it violates one of the language's safety invariants). So 
if you've found a memory safety violation, it is always possible 
to use it to create an example of UB in @safe code.

The above example is neither memory-unsafe nor UB. According to 
the spec, it prints an implementation-defined value of type int.


More information about the Digitalmars-d mailing list