base: Add a static assert to check bit union ranges

If a bit field in a bit union specified as Bitfield<LSB, MSB> instead
of Bitfield<MSB, LSB> the code silently fails and the field is read as
zero. This changeset introduces a static assert that tests, at compile
time, that the bit order is correct.
This commit is contained in:
Andreas Sandberg
2014-08-26 10:13:28 -04:00
parent a3d3eb0ff7
commit 61b8d5e4e4

View File

@@ -85,6 +85,9 @@ namespace BitfieldBackend
template<int first, int last=first>
class Bitfield : public BitfieldBase<Type>
{
static_assert(first >= last,
"Bitfield ranges must be specified as <msb, lsb>");
public:
operator const uint64_t () const
{