digitalmars.D.bugs - [Issue 22710] New: Different behaviour of bitfields between CTFE and
- d-bugmail puremagic.com (34/34) Jan 28 2022 https://issues.dlang.org/show_bug.cgi?id=22710
https://issues.dlang.org/show_bug.cgi?id=22710 Issue ID: 22710 Summary: Different behaviour of bitfields between CTFE and runtime Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: major Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: moonlightsentinel disroot.org The CTFE engine ins't aware of the subtle differences of bitfields vs normal variables. This manifests e.g. in incorrect overflow behaviour: --- app.d import bitfields; extern(C) int main() { HasBitfield bf; bf.a += 4; assert(bf.a == 0); // Fails during CTFE assert(bf.b == 0); return 0; } enum test = main(); --- bitfields.c struct HasBitfield { int a : 2; int b : 2; }; --
Jan 28 2022