From 61b8d5e4e4b27010f5dd757a34e7295bb5dd10ff Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Tue, 26 Aug 2014 10:13:28 -0400 Subject: [PATCH] base: Add a static assert to check bit union ranges If a bit field in a bit union specified as Bitfield instead of Bitfield 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. --- src/base/bitunion.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/base/bitunion.hh b/src/base/bitunion.hh index f640fa3b1..190c1a5e1 100644 --- a/src/base/bitunion.hh +++ b/src/base/bitunion.hh @@ -85,6 +85,9 @@ namespace BitfieldBackend template class Bitfield : public BitfieldBase { + static_assert(first >= last, + "Bitfield ranges must be specified as "); + public: operator const uint64_t () const { -- 2.30.2