Skip to content

Commit

Permalink
#1509 Fix warnings in enum.hpp high bit calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeletier authored Jan 10, 2025
1 parent 95bf590 commit fbb7c0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18053,8 +18053,10 @@ struct enum_reflection {
static constexpr U each_enum(Args... args) {
return each_mask_range<Value, high_bit>(each_enum_range<0, Value>(0, args...), args...);
}

static const U high_bit = static_cast<U>(1) << (sizeof(U) * 8 - 1);
/* to avoid warnings with bit manipulation, calculate the high bit with an
unsigned type of the same size: */
using UU = typename std::make_unsigned<U>::type;
static const U high_bit = static_cast<U>(static_cast<UU>(1) << (sizeof(UU) * 8 - 1));
};

/** Enumeration type data */
Expand Down
6 changes: 4 additions & 2 deletions include/flecs/addons/cpp/utils/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ struct enum_reflection {
static constexpr U each_enum(Args... args) {
return each_mask_range<Value, high_bit>(each_enum_range<0, Value>(0, args...), args...);
}

static const U high_bit = static_cast<U>(1) << (sizeof(U) * 8 - 1);
/* to avoid warnings with bit manipulation, calculate the high bit with an
unsigned type of the same size: */
using UU = typename std::make_unsigned<U>::type;
static const U high_bit = static_cast<U>(static_cast<UU>(1) << (sizeof(UU) * 8 - 1));
};

/** Enumeration type data */
Expand Down

0 comments on commit fbb7c0c

Please sign in to comment.