From 08a84f844a221b8582f2de102f48775cae69b8bb Mon Sep 17 00:00:00 2001 From: fesseha-eve <88329315+fessehaeve@users.noreply.github.com> Date: Wed, 29 Nov 2023 04:36:00 +0100 Subject: [PATCH] Fix type conversion error in BitFlags Clear (#30680) * attempt to fix failing CI * added test for BitMask Clear function --- src/lib/support/BitFlags.h | 2 +- src/lib/support/tests/TestBitMask.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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() // };