Bug 21635 – std.bitmanip: bitfields should produce better error messages with wrong parameters
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-02-13T10:41:41Z
Last change time
2021-02-16T13:02:10Z
Keywords
pull
Assigned to
No Owner
Creator
Berni44
Comments
Comment #0 by bugzilla — 2021-02-13T10:41:41Z
struct A
{
mixin(bitfields!(uint));
}
struct B
{
mixin(bitfields!(uint, "x"));
}
struct C
{
mixin(bitfields!(uint, 3, 8));
}
struct D
{
mixin(bitfields!(uint, "x", "x"));
}
struct E
{
mixin(bitfields!(float, "x", 32));
}
struct F
{
mixin(bitfields!(ulong, "a", 32,
ulong, "b", -32,
ulong, "c", 32,
ulong, "d", 32));
}
struct G
{
mixin(bitfields!(ulong, "x", 8,
ulong, "x", 8));
}
The error messages generated by these look like this; they could be better
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(186): Error: tuple index 1 exceeds 1
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(186): Error: tuple index 2 exceeds 1
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(187): Error: array index `[2]` is outside array bounds `[0 .. 1]`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(187): Error: slice `[3..1]` is out of range of `[0..1]`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(179): Error: template instance `std.bitmanip.createFields!("", 0LU, uint)` error instantiating
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(262): instantiated from here: `createStorageAndFields!uint`
test.d(5): instantiated from here: `bitfields!uint`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(157): Error: slice `[3..2]` is out of range of [0..2]
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(162): Error: template instance `std.bitmanip.createStoreName!(uint, "x")` error instantiating
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(262): instantiated from here: `createStorageAndFields!(uint, "x")`
test.d(10): instantiated from here: `bitfields!(uint, "x")`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(234): Error: array index `[2]` is outside array bounds `[0 .. 2]`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(234): Error: slice `[3..2]` is out of range of [0..2]
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(163): Error: template instance `std.bitmanip.sizeOfBitField!(uint, "x")` error instantiating
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(262): instantiated from here: `createStorageAndFields!(uint, "x")`
test.d(10): instantiated from here: `bitfields!(uint, "x")`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(186): Error: template instance `createAccessors!("_\x03", uint, 3, 8, 0LU)` does not match template declaration `createAccessors(string store, T, string name, ulong len, ulong offset)`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(179): Error: template instance `std.bitmanip.createFields!("_\x03", 0LU, uint, 3, 8)` error instantiating
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(262): instantiated from here: `createStorageAndFields!(uint, 3, 8)`
test.d(15): instantiated from here: `bitfields!(uint, 3, 8)`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(234): Error: incompatible types for `("x") + (0)`: `string` and `int`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(163): Error: template instance `std.bitmanip.sizeOfBitField!(uint, "x", "x")` error instantiating
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(262): instantiated from here: `createStorageAndFields!(uint, "x", "x")`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(96): Error: no property `min` for type `float`, perhaps `import std.algorithm;` is needed?
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(130): Error: no property `min` for type `float`, perhaps `import std.algorithm;` is needed?
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(186): Error: template instance `std.bitmanip.createAccessors!("_x", float, "x", 32LU, 0LU)` error instantiating
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(179): instantiated from here: `createFields!("_x", 0LU, float, "x", 32)`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(262): instantiated from here: `createStorageAndFields!(float, "x", 32)`
test.d(25): instantiated from here: `bitfields!(float, "x", 32)`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(93): Error: shift by 96 is outside the range `0..63`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(94): Error: shift by -33 is outside the range `0..63`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(106): Error: shift by 96 is outside the range `0..63`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(186): Error: template instance `std.bitmanip.createAccessors!("_a_b_c_d", ulong, "b", 18446744073709551584LU, 32LU)` error instantiating
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(187): instantiated from here: `createFields!("_a_b_c_d", 32LU, ulong, "b", -32, ulong, "c", 32, ulong, "d", 32)`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(179): instantiated from here: `createFields!("_a_b_c_d", 0LU, ulong, "a", 32, ulong, "b", -32, ulong, "c", 32, ulong, "d", 32)`
/home/D/Repo/dmd/generated/linux/release/64/../../../../../phobos/std/bitmanip.d(262): instantiated from here: `createStorageAndFields!(ulong, "a", 32, ulong, "b", -32, ulong, "c", 32, ulong, "d", 32)`
test.d(30): instantiated from here: `bitfields!(ulong, "a", 32, ulong, "b", -32, ulong, "c", 32, ulong, "d", 32)`
test.d-mixin-38(42): Error: variable `test.G.x_min` conflicts with variable `test.G.x_min` at test.d-mixin-38(40)
test.d-mixin-38(42): Error: variable `test.G.x_max` conflicts with variable `test.G.x_max` at test.d-mixin-38(40)
Comment #1 by dlang-bot — 2021-02-13T13:32:15Z
@berni44 created dlang/phobos pull request #7793 "Fix issues 21635 and 21636 - check parameters of bitfields" fixing this issue:
- Fix issue 21635 - std.bitmanip: bitfields should produce better error messages with wrong parameters
Fix issue 21636 - std.bitmanip: bitfields size of bitfield should be checked against size of used type
https://github.com/dlang/phobos/pull/7793
Comment #2 by dlang-bot — 2021-02-16T13:02:10Z
dlang/phobos pull request #7793 "Fix issues 21635 and 21636 - check parameters of bitfields" was merged into master:
- 50b89cdcacd3ffd36ee2cf7f17d7cb9c611ee939 by berni44:
Fix issues 21635, 21636:
std.bitmanip: bitfields should produce better error messages with wrong parameters
std.bitmanip: bitfields size of bitfield should be checked against size of used type
https://github.com/dlang/phobos/pull/7793