[Issue 21855] New: CTFE anonymous union assignment inconsistent

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 23 16:53:24 UTC 2021


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 at puremagic.com
          Reporter: paultjeadriaanse at 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);
}

--


More information about the Digitalmars-d-bugs mailing list