Skip to content

Commit b8ef2d4

Browse files
authored
Merge 3b50bae into sapling-pr-archive-ktf
2 parents 7c6af38 + 3b50bae commit b8ef2d4

File tree

13 files changed

+536
-217
lines changed

13 files changed

+536
-217
lines changed

Common/Utils/include/CommonUtils/EnumFlags.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ struct FlagsHelper final {
160160
static constexpr auto Max_v{Values.back()}; // Enum last entry
161161
static constexpr auto Min_u_v{static_cast<size_t>(Min_v)}; // Enum first entry as size_t
162162
static constexpr auto Max_u_v{static_cast<size_t>(Max_v)}; // Enum last entry as size_t
163-
static constexpr bool isContinuous() noexcept { return (Max_u_v - Min_u_v + 1) == count(); } // Is the enum continuous
164-
static constexpr auto MaxRep{((1 << (Max_u_v - Min_u_v + 1)) - 1) << Min_u_v}; // largest representable value
163+
static_assert(Max_u_v < std::numeric_limits<U>::digits, "Max Bit is beyond allow range defered from underlying type");
164+
static constexpr bool isContinuous() noexcept { return (Max_u_v - Min_u_v + 1) == count(); } // Is the enum continuous
165+
static constexpr auto MaxRep{((1ULL << (static_cast<unsigned long long>(Max_u_v - Min_u_v) + 1ULL)) - 1ULL) << Min_u_v}; // largest representable value
165166

166167
template <E e>
167168
static constexpr std::string_view getName()

Common/Utils/test/testEnumFlags.cxx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,46 @@ enum class TestEnum : uint8_t {
2828
Bit5VeryLongName,
2929
};
3030

31+
// Very long enum
32+
// to test that it works beyond 32 bits
33+
enum class TestEnumLong : uint64_t {
34+
Bit1,
35+
Bit2,
36+
Bit3,
37+
Bit4,
38+
Bit5,
39+
Bit6,
40+
Bit7,
41+
Bit8,
42+
Bit9,
43+
Bit10,
44+
Bit11,
45+
Bit12,
46+
Bit13,
47+
Bit14,
48+
Bit15,
49+
Bit16,
50+
Bit17,
51+
Bit18,
52+
Bit19,
53+
Bit20,
54+
Bit21,
55+
Bit22,
56+
Bit23,
57+
Bit24,
58+
Bit25,
59+
Bit26,
60+
Bit27,
61+
Bit28,
62+
Bit29,
63+
Bit30,
64+
Bit31,
65+
Bit32,
66+
Bit33,
67+
Bit34,
68+
// ...
69+
};
70+
3171
BOOST_AUTO_TEST_CASE(Flags_test)
3272
{
3373
using EFlags = o2::utils::EnumFlags<TestEnum>;
@@ -257,4 +297,11 @@ BOOST_AUTO_TEST_CASE(Flags_test)
257297
EFlags flags3{TestEnum::Bit4};
258298
BOOST_CHECK(!flags1.contains(flags3)); // flags1 does not contain flags3
259299
}
300+
301+
{
302+
// Test compilation using an enum with more than 32 bits
303+
o2::utils::EnumFlags<TestEnumLong> test;
304+
test.set("Bit32");
305+
BOOST_CHECK(test.test(TestEnumLong::Bit32));
306+
}
260307
}

0 commit comments

Comments
 (0)