Bug 15305 – std.manip.bitfields generate bogous code

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2015-11-09T02:28:00Z
Last change time
2016-01-03T14:15:01Z
Assigned to
nobody
Creator
deadalnix

Comments

Comment #0 by deadalnix — 2015-11-09T02:28:12Z
import std.bitmanip; struct S { mixin(bitfields!( bool, "alice", 1, ulong, "bob", 63, )); } S s; s.bob = long.max - 1; s.alice = false; assert(s.bob == long.max - 1); Setting alice to false is clearing bits in bob, while it really shouldn't.
Comment #1 by lio+bugzilla — 2015-11-16T11:10:14Z
The generated setter for alice is wrong: @property void alice(bool v) @safe pure nothrow @nogc { if (v) _alice_bob |= 1U;else _alice_bob &= ~1U;} and it's wrong because the &=~1U would clear not just the first bit, but bits 32-64 as well. This in turn because of the code in myToString, which picks the smallest type suffix, "U" in this case.
Comment #2 by lio+bugzilla — 2015-11-16T11:20:40Z
Comment #3 by github-bugzilla — 2015-11-16T12:45:25Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/8e452d8dd484866a6be2c3c180a664ee57b16905 [Issue 15305] bitfields! setter erroneously clears subsequent fields https://github.com/D-Programming-Language/phobos/commit/4e53643652b8e927965c9888c35859c2a81bd56a Merge pull request #3815 from lionello/issue15305 [Issue 15305] bitfields! setter erroneously clears subsequent fields
Comment #4 by github-bugzilla — 2016-01-03T14:15:01Z