Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions std/bitmanip.d
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ private template createAccessors(
~ " return cast("~T.stringof~") result;}\n"
// setter
~"@property @safe void "~name~"("~T.stringof~" v) pure nothrow { "
~"assert(v >= "~name~"_min); "
~"assert(v <= "~name~"_max); "
~"assert(v >= "~name~`_min, "Value is smaller than the minimum value of bitfield '`~name~`'"); `
~"assert(v <= "~name~`_max, "Value is greater than the maximum value of bitfield '`~name~`'"); `
~store~" = cast(typeof("~store~"))"
~" (("~store~" & ~cast(typeof("~store~"))"~myToString(maskAllElse)~")"
~" | ((cast(typeof("~store~")) v << "~myToString(offset)~")"
Expand Down Expand Up @@ -416,6 +416,30 @@ unittest
assert(f.checkExpectations(true));
}

// Issue 12477
unittest
{
import std.bitmanip : bitfields;
import core.exception : AssertError;

static struct S
{
mixin(bitfields!(
uint, "a", 6,
int, "b", 2));
}

S s;

try { s.a = uint.max; assert(0); }
catch (AssertError ae)
{ assert(ae.msg == "Value is greater than the maximum value of bitfield 'a'", ae.msg); }

try { s.b = int.min; assert(0); }
catch (AssertError ae)
{ assert(ae.msg == "Value is smaller than the minimum value of bitfield 'b'", ae.msg); }
}

/**
Allows manipulating the fraction, exponent, and sign parts of a
$(D_PARAM float) separately. The definition is:
Expand Down