From: Andreas Sandberg Date: Tue, 26 Aug 2014 14:13:28 +0000 (-0400) Subject: base: Add a static assert to check bit union ranges X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=61b8d5e4e4b27010f5dd757a34e7295bb5dd10ff;p=gem5.git 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. --- 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 {