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:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user