diff --git a/src/lib/support/BitFlags.h b/src/lib/support/BitFlags.h index 3cc7dc4a24fdb2..c1f7efb80611ca 100644 --- a/src/lib/support/BitFlags.h +++ b/src/lib/support/BitFlags.h @@ -102,7 +102,7 @@ class BitFlags */ BitFlags & Clear(const BitFlags & other) { - mValue &= ~other.mValue; + mValue &= static_cast(~static_cast(other.mValue)); return *this; } diff --git a/src/lib/support/tests/TestBitMask.cpp b/src/lib/support/tests/TestBitMask.cpp index 1745f9295cc126..5405fb17c2c3d7 100644 --- a/src/lib/support/tests/TestBitMask.cpp +++ b/src/lib/support/tests/TestBitMask.cpp @@ -98,10 +98,26 @@ void TestBitMaskInvalid(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, mask.Raw() == 0x1234); } +void TestClear(nlTestSuite * inSuite, void * inContext) +{ + BitMask mask1; + BitMask mask2; + + mask1.Set(TestEnum::kBit_0); + mask1.Set(TestEnum::kBits_1_2); + mask1.Set(TestEnum::kBits_High8); + + mask2.Set(TestEnum::kBits_1_2); + mask1.Clear(mask2); + + NL_TEST_ASSERT(inSuite, mask1.Raw() == 0xFF01); +} + const nlTest sTests[] = { NL_TEST_DEF("BitMask operations", TestBitMaskOperations), // NL_TEST_DEF("BitFields logic", TestBitFieldLogic), // NL_TEST_DEF("Invalid operations", TestBitMaskInvalid), // + NL_TEST_DEF("Clear operations", TestClear), // NL_TEST_SENTINEL() // };