diff --git a/libraries/AP_Common/Bitmask.h b/libraries/AP_Common/Bitmask.h index 4b14de01b3..24ee2fcf1b 100644 --- a/libraries/AP_Common/Bitmask.h +++ b/libraries/AP_Common/Bitmask.h @@ -25,6 +25,12 @@ template class Bitmask { + static_assert(num_bits > 0, "must store something"); + // for first_set()'s return value + static_assert(num_bits <= INT16_MAX, "must fit in int16_t"); + // so that 1U << bits is in range + static_assert(sizeof(unsigned int) >= sizeof(uint32_t), "int too small"); + public: Bitmask() : numbits(num_bits), @@ -122,13 +128,7 @@ public: uint16_t count() const { uint16_t sum = 0; for (uint16_t i=0; i