Lowerings to strongly pure _d_arrayctor trigger warnings or risk being incorrectly removed
Paul Backus
snarwin at gmail.com
Tue Oct 12 18:27:53 UTC 2021
On Tuesday, 12 October 2021 at 18:04:21 UTC, Teodor Dutu wrote:
>
> I have read the documentation at the links you left, but I
> can't see why the usage of `_d_arrayctor` would be an undefined
> behaviour.
`_d_arrayctor` casts away `immutable` internally--either
[here][1], directly, or [here][2] indirectly via `copyEmplace`
(which casts it away [here][3]). It then uses `memcpy` to mutate
the memory that was originally typed as `immutable`. This is
undefined behavior, according to the language spec.
[1]:
https://github.com/dlang/druntime/blob/16c836a7b084b935504427579e2d646c462ee6e4/src/core/internal/array/construction.d#L77
[2]:
https://github.com/dlang/druntime/blob/16c836a7b084b935504427579e2d646c462ee6e4/src/core/internal/array/construction.d#L59
[3]:
https://github.com/dlang/druntime/blob/16c836a7b084b935504427579e2d646c462ee6e4/src/core/lifetime.d#L1239
> This lowering only occurs when initialising static arrays or
> slices
The spec does not currently make an exception for initializing
static arrays or slices, so the fact that it only occurs in that
context does not make any difference to whether the spec
considers it UB.
More information about the Digitalmars-d
mailing list