D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21636 - std.bitmanip: bitfields size of bitfield should be checked against size of used type
Summary: std.bitmanip: bitfields size of bitfield should be checked against size of us...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-02-13 10:46 UTC by Berni44
Modified: 2021-02-16 13:02 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Berni44 2021-02-13 10:46:09 UTC
struct A
{
    mixin(bitfields!(byte, "x", 32));
}

unittest
{
    A a;
    a.x = 17;
}

produces

test.d-mixin-5(6): [unittest] Value is greater than the maximum value of bitfield 'x'

The reason is, that a byte cannot hold 32 bits.
Comment 1 Dlang Bot 2021-02-16 09:14:43 UTC
@berni44 updated dlang/phobos pull request #7793 "Fix issues 21635 and 21636 - check parameters of bitfields" fixing this issue:

- 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
Comment 2 Dlang Bot 2021-02-16 13:02:11 UTC
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