Skip to content

Commit d97417b

Browse files
committed
Fix EnumFlags compilation for large enums
The EnumFlags fails to compile when the underlying enum has 30 or more elements. With exactly 32 elements the compilation error is the following: note: shift count 32 >= width of type 'int' (32 bits) static constexpr auto MaxRep{((1 << (Max_u_v - Min_u_v + 1)) - 1) << Min_u_v}; // largest representable value With 30 or 31 elements the compilation error is: note: value -2147483649 is outside the range of representable values of type 'int' static constexpr auto MaxRep{((1 << (Max_u_v - Min_u_v + 1)) - 1) << Min_u_v}; // largest representable value The solution consists in casting to unint64_t the first "1" in the MaxRep expression, such that the bit shifts are performed on a 64-bit variable.
1 parent f37a28b commit d97417b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Common/Utils/include/CommonUtils/EnumFlags.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ struct FlagsHelper final {
154154
}
155155
return values;
156156
}
157-
static constexpr auto Values{getValues(std::make_index_sequence<MaxScan - MinScan - MarginScan>())}; // Enum Values
158-
static constexpr auto count() noexcept { return Values.size(); } // Number of enum members
159-
static constexpr auto Min_v{Values.front()}; // Enum first entry
160-
static constexpr auto Max_v{Values.back()}; // Enum last entry
161-
static constexpr auto Min_u_v{static_cast<size_t>(Min_v)}; // Enum first entry as size_t
162-
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
157+
static constexpr auto Values{getValues(std::make_index_sequence<MaxScan - MinScan - MarginScan>())}; // Enum Values
158+
static constexpr auto count() noexcept { return Values.size(); } // Number of enum members
159+
static constexpr auto Min_v{Values.front()}; // Enum first entry
160+
static constexpr auto Max_v{Values.back()}; // Enum last entry
161+
static constexpr auto Min_u_v{static_cast<size_t>(Min_v)}; // Enum first entry as size_t
162+
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{((static_cast<uint64_t>(1) << (Max_u_v - Min_u_v + 1)) - 1) << Min_u_v}; // largest representable value
165165

166166
template <E e>
167167
static constexpr std::string_view getName()

0 commit comments

Comments
 (0)