Is the following well defined and allowed?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Mar 1 21:09:00 UTC 2018


On Thursday, March 01, 2018 16:01:08 Steven Schveighoffer via Digitalmars-d 
wrote:
> 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.

IMHO, it was a mistake to ever add it.

> > 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.

That depends on the feature. It's true for array bounds checking, but it's
not true for stuff like final switch statements - or apparently, this
situation. I don't know if that should be changed or not. Probably.

- Jonathan M Davis



More information about the Digitalmars-d mailing list