Strange behavior when concatenating array

Steven Schveighoffer schveiguy at yahoo.com
Fri Jun 17 19:03:12 PDT 2011


On Fri, 17 Jun 2011 18:52:05 -0400, Timon Gehr <timon.gehr at gmx.ch> wrote:

> Steven Schveighoffer wrote:
>> https://github.com/D-Programming-Language/druntime/pull/29
>>
>> See if that helps.  On my system, your code now results in your expected
>> output.
>>
>> -Steve
>
> If the compiler optimizes well enough the output given could be valid  
> (it might
> construct the struct directly where it belongs). This needs some  
> investigation.
> Anyways, is druntime the correct place to fix this? If it _is_ a bug,  
> isn't it a
> compiler bug and not a bug in druntime? After a quick glimpse over your  
> patch I
> think the output will never be just "done" now.

The patch is still necessary in cases where the value being appended is  
not a temporary.  For example, if in the OP's code the test variable was  
used after appending it to the array.

Michel Fortin also brought up the point in a comment on the pull request.   
But the reality is, druntime cannot do any better without help from the  
compiler (the runtime needs to be told when to refrain from running a  
postblit).  It's a separate bug.

However, I think there is nothing invalid with doing both the postblit and  
the destructor on the temporary.  So at least the code is correctly  
calling the postblit.

-Steve


More information about the Digitalmars-d-learn mailing list