dip1000 and preview in combine to cause extra safety errors

Walter Bright newshound2 at digitalmars.com
Fri Jun 10 03:15:37 UTC 2022


On 6/9/2022 5:58 AM, Timon Gehr wrote:
> But if the compiler can easily tell that something makes no sense, it should 
> still be an error in both `@safe` and `@system` code!

Sometimes it makes sense for a function to return the address of a local. For 
example, if you want to detect how large the stack has gotten. I use this in, 
for example, the garbage collector to see how much stack needs to be scanned. It 
can also be used to "step" on the stack after a function returns, as one might 
want to do for security software.

I've also done things like write 0xDEADBEEF all over memory in order to flush 
out memory bugs. This involves using pointers in UB ways that don't make sense 
as far as the language is concerned.

In @safe code it is nonsense to write specific numbers into a pointer. But in 
@system code, it does make sense.

I don't think one could write a symbolic debugger with @safe code. Like writing 
instruction bytes into a buffer, and then calling it? How unsafe can one get? :-)

And so on.


More information about the Digitalmars-d mailing list