Possible bug when instantiating template function with nested struct

Teodor Dutu teodor.dutu at gmail.com
Sun Nov 7 17:47:45 UTC 2021


On Sunday, 7 November 2021 at 17:01:20 UTC, Stanislav Blinov 
wrote:
> On Sunday, 7 November 2021 at 16:07:19 UTC, Teodor Dutu wrote:
>> I think the issue of array representation is a serious enough 
>> topic that it deserves its own separate thread. In addition, 
>> this issue is outside the scope of initial question, which 
>> revolves around the bug highlighted here:
>> - https://issues.dlang.org/show_bug.cgi?id=8850
>> - https://issues.dlang.org/show_bug.cgi?id=8863
>>
>> Do you have any suggestions about it?
>
> void-initialize your to-be-returned array in _d_arrayctor?

Won't this be the same as doing this:
```d
T[] to;  // to be returned
to.length = length;
```
The problem with this approach is that `to` isn't NRVO'd because 
the lowering to `_d_arrayctor` is only done for static arrays.

> Which BTW should also bring your attention to the fact that 
> such a function can never be @trusted, and can only be as @safe 
> as the actual ctor calls it would defer to.

I used `@trusted` because some unittests that used this lowering 
were `@safe`. It was a compile-time workaround.




More information about the Digitalmars-d mailing list