Is "auto t=T();" not the same as "T t;"?

Ali Çehreli acehreli at yahoo.com
Tue Oct 25 15:32:48 UTC 2022


On 10/25/22 07:53, Adam D Ruppe wrote:
 > On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote:
 >>     A[] a = [A.init];
 >
 > This is a problem - this is referring to a static array instance, shared
 > across all copies of B. You almost certainly don't want this.

Agreed. It should be fine when the elements are immutable as I've 
experimented with recently[1]:

struct Xml {
     string beg;
     string end = "/>";  // Shared by all instances;
                         // no allocation for some objects.
// ...
}

 > As for why B() and B.init are different here... i don't know, probably
 > some subtly of the compiler's implementation.

I think it's a bug.

Ali

[1] https://youtu.be/0JL9uT_XGZE?t=4260s



More information about the Digitalmars-d-learn mailing list