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.


> 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