Bug 12477 – std.bitmanip should emit informative diagnostics
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-26T15:50:00Z
Last change time
2014-04-28T11:17:16Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2014-03-26T15:50:07Z
-----
import std.bitmanip;
struct S
{
mixin(bitfields!(
uint, "a", 6,
uint, "b", 10));
}
void main()
{
S s;
s.a = uint.max;
}
-----
$ dmd -g -run test.d
-----
[email protected](8): Assertion failure
----------------
0x0040240B in _d_assert
0x0040217D in _Dmain at C:\dev\code\d_code\test.d(15)
0x00402704 in D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv
0x004026D7 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()
0x004025F0 in _d_run_main
0x00402198 in main
0x004189DD in mainCRTStartup
0x75803677 in BaseThreadInitThunk
0x778A9D72 in __RtlUserThreadStart
0x778A9D45 in _RtlUserThreadStart
-----
The number is out of range for the bitfield size, but the diagnostic doesn't say that.
Comment #1 by bearophile_hugs — 2014-03-26T16:32:46Z
It's not easy to work on the implementation of std.bitmanip.bitfields. The code is not simple.
Comment #2 by safety0ff.bugz — 2014-03-26T21:52:23Z
Comment #3 by andrej.mitrovich — 2014-03-27T04:12:59Z
(In reply to comment #2)
> (In reply to comment #1)
> > It's not easy to work on the implementation of std.bitmanip.bitfields. The code
> > is not simple.
>
> It's not that bad,
> https://github.com/D-Programming-Language/phobos/blob/master/std/bitmanip.d#L116
> just need to have error messages added to them.
I don't know when that code was written, but maybe we can replace it with templates nowadays instead of using string mixins. It would make things much more readable (and probably faster to compile).
Comment #4 by safety0ff.bugz — 2014-03-27T04:31:49Z
(In reply to comment #3)
> I don't know when that code was written, but maybe we can replace it with
> templates nowadays instead of using string mixins. It would make things much
> more readable (and probably faster to compile).
I think re-writing bitfield is pretty low bang for buck (unless somebody already has a mental skeleton/sketch of an implementation.)
Comment #5 by andrej.mitrovich — 2014-04-23T19:49:46Z