digitalmars.D.bugs - [Issue 18930] New: __ctfe fails to detect initialization of unions
- d-bugmail puremagic.com (48/48) May 31 2018 https://issues.dlang.org/show_bug.cgi?id=18930
https://issues.dlang.org/show_bug.cgi?id=18930 Issue ID: 18930 Summary: __ctfe fails to detect initialization of unions Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: major Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: johnnymarler gmail.com ------------------------------- union TwoInts { struct { int _0; int _1; } int[2] array; } private int sum() { auto twoValues = TwoInts(); twoValues._0 = 100; twoValues._1 = 200; int x; foreach(i; 0..2) { x += twoValues.array[i]; } return x; } //enum v = sum(); // ERROR void main() { import core.stdc.stdio; printf("sum is %d\n", sum()); } ------------------------------- If you uncomment the `enum v = sum();` AND comment out the print line you'll get this error: bug.d(18): Error: `twoValues.array[cast(uint)i]` is used before initialized bug.d(6): originally uninitialized here bug.d(23): called from here: `sum()` --
May 31 2018