digitalmars.D.bugs - [Issue 21855] New: CTFE anonymous union assignment inconsistent
- d-bugmail puremagic.com (39/39) Apr 23 2021 https://issues.dlang.org/show_bug.cgi?id=21855
https://issues.dlang.org/show_bug.cgi?id=21855 Issue ID: 21855 Summary: CTFE anonymous union assignment inconsistent Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: paultjeadriaanse gmail.com 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/gaaqqpmisrxgukfducxi forum.dlang.org 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); } --
Apr 23 2021