You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
union U
{
struct S
{
long l;
}
int i;
S s;
}
enum ctfeInit = {
U u;
u.s.l = 1;
return u;
}();
void main()
{
static a = ctfeInit;
auto b = ctfeInit;
assert(a is b);
}
Assert fails because what CTFE generates is:
enum U ctfeInit = U(0, S(1L));
And dmd backend codegen for static initializers ignores overlapping fields, resulting in the value becoming U(0), while the runtime initializer sets each field individually as b.i = 0; b.s.l = 1;.
Workaround is to declare variable as being void initialized.
enum ctfeInit = {
U u = void;
u.s.l = 1;
return u;
}();
This results in the correct value being generated.
enum U ctfeInit = U(, S(1L));
The text was updated successfully, but these errors were encountered:
ibuclaw
added a commit
to ibuclaw/phobos
that referenced
this issue
Jan 10, 2025
Reduced from dlang/phobos#9064
Assert fails because what CTFE generates is:
And dmd backend codegen for static initializers ignores overlapping fields, resulting in the value becoming
U(0)
, while the runtime initializer sets each field individually asb.i = 0; b.s.l = 1;
.Workaround is to declare variable as being void initialized.
This results in the correct value being generated.
The text was updated successfully, but these errors were encountered: