Choosing an Approach for the Template Lowering of _d_arrayctor

Teodor Dutu teodor.dutu at gmail.com
Thu Nov 25 14:35:56 UTC 2021


On Thursday, 25 November 2021 at 14:24:59 UTC, Stanislav Blinov 
wrote:
> On Thursday, 25 November 2021 at 13:28:18 UTC, Teodor Dutu 
> wrote:
>
>> A third approach, which I call the **hack** approach, is very 
>> close to the one using the template. The difference is that 
>> the hack adds a third, unused, pointer-type parameter...
>
> Hm... if you're going to have a pointer parameter, why not 
> instead simply keep the two parameter variant but pass the 
> first parameter by reference?

The first iteration of `_d_arrayctor` was like this, as 
implemented by [this 
PR](https://github.com/dlang/druntime/pull/2655). The problem 
with it was that it made the compiler issue some warnings when 
testing phobos, because the lowering of something like `S[3] dst 
= src;` looked like this: `_d_arrayctor(dst[], src[])`. 
`_d_arrayctor` was strongly pure and, since the return value of 
the function was ignored, the compiler deemed the whole function 
call useless.

I went more in-depth about this problem in [this 
post](https://forum.dlang.org/post/simesvkancmscrtsciwq@forum.dlang.org). Following this, I tried to change `_d_arrayctor` to declare the returned array inside its own scope, hoping to make use of NRVO, but it wasn't the case, because I had to resort to the union trick.


More information about the Digitalmars-d mailing list