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

Salih Dincer salihdb at hotmail.com
Tue Oct 25 16:52:48 UTC 2022


On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov 
wrote:
> Does the second piece of code shows a bug or my expectation is 
> not correct (and why if so)?

This is a bug:

```d
void main()
{
   struct B
   {
     struct A
     {
       int i = 10;
     }
     A[] a = [A.init];
   }

   B[2] b;
   assert(b[0].a[0].i == 10);
   assert(b[1].a[0].i == 10);

   b[0].a[0].i = 1;
   assert(b[0].a[0].i == 1); // ok...
   assert(b[1].a[0].i == 1); // must be 10 !!!
}
```

SDB at 79


More information about the Digitalmars-d-learn mailing list