Skip to content

Commit

Permalink
Merge pull request #2113 from AndrejMitrovic/Fix12477
Browse files Browse the repository at this point in the history
Issue 12477 - std.bitmanip should emit informative diagnostics.
  • Loading branch information
monarchdodra committed Apr 28, 2014
2 parents f2c630a + ccd1e20 commit 33e6067
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions std/bitmanip.d
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

0 comments on commit 33e6067

Please sign in to comment.