Bug 21855 – CTFE anonymous union assignment inconsistent

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2021-04-23T16:53:24Z
Last change time
2024-12-13T19:15:53Z
Assigned to
No Owner
Creator
paultjeadriaanse
Moved to GitHub: dmd#19909 →

Comments

Comment #0 by paultjeadriaanse — 2021-04-23T16:53:24Z
The following code behaves differently, depending on whether the .a or the .b field is used. The forum post may be more informative: https://forum.dlang.org/post/[email protected] import std.stdio; struct Apple(uint size) { union { int[size * size] a; int[size][size] b; } static immutable typeof(this) pie = _pie(); private static typeof(this) _pie() pure { typeof(this) result; static foreach (i; 0 .. size) static foreach (j; 0 .. size) //result.a[i + j * size] = 1; // Works result.b[i][j] = 1; // Fails return result; } } void main() { Apple!(4) a = Apple!(4).pie; writeln(a.a); writeln(a.b); }
Comment #1 by robert.schadek — 2024-12-13T19:15:53Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19909 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB