[Issue 15938] ctor doesn't initialize fields when struct is static immutable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 24 15:23:58 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=15938
RazvanN <razvan.nitu1305 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |razvan.nitu1305 at gmail.com
--- Comment #3 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to John Colvin from comment #2)
> Simplified example:
>
> struct S {
> union {
> // works if order swapped
> int b;
> int[1] a;
> }
>
> this(int v) {
> a[0] = v;
> }
> }
> auto s = S(2);
>
> void main() {
> assert(s.a[0] == 2); // fails
> assert(S(2).a[0] == 2); // OK
> }
It seems that ctfe rewrites `auto s = S(2)` to `auto s = S(0, [2)`. So it does
not seem to understand that a and b are inside a union and therefore only the
first initializer (0) will be taken into account.
--
More information about the Digitalmars-d-bugs
mailing list