On 3/1/18 3:24 PM, ag0aep6g wrote:
On Thursday, 1 March 2018 at 20:14:07 UTC, Steven Schveighoffer wrote:
dmd -version=dosafe -noboundscheck -run testarrayoverlap.d => no error, undefined behavior
dmd -run testarrayoverlap.d => error

@safe has nothing to do with it.

@safe has everything to do with. @safe guarantees that there's no undefined behavior. If you can trigger UB in @safe code, that's a bug. The guarantee must hold whether asserts are enabled or not. -noboundscheck does not just disable asserts, it undermines @safe, rendering it meaningless.

Yeah, it seems like -noboundscheck should never be used.

It's undefined behavior if the check is disabled. How you get the check disabled may be affected by @safe, but whether it's UB or not has nothing to do with @safe. It has to do with "I turned off the checks". Basically, in D, if your program *would have* thrown an Error, but didn't because you turned it off, the compiler is free to assume UB.


For just disabling asserts (without affecting @safe), there's -release. With your same code, `dmd -release` => UB, but `dmd -release -version=dosafe` => Error.

I was unaware that it would work this way. I thought it would be the same whether you used @safe or not with -release.

-Steve

Reply via email to