Bug 1614512 - Give mozilla::Side and mozilla::Corner a fixed underlying type. r=froydnj

So as to avoid UB. It is somewhat unfortunate/dumb the fact that we need to do
this and we can't detect when we forget to do it :(

Give it uint8_t as it's type as that's enough and consistent with LogicalSide.

Differential Revision: https://phabricator.services.mozilla.com/D62390

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2020-02-11 14:11:06 +00:00
Родитель d15ef2041e
Коммит 6311bc2129
2 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -514,7 +514,7 @@ typedef mozilla::gfx::SurfaceFormat gfxImageFormat;
namespace mozilla {
// Side constants for use in various places.
enum Side { eSideTop, eSideRight, eSideBottom, eSideLeft };
enum Side : uint8_t { eSideTop, eSideRight, eSideBottom, eSideLeft };
constexpr auto AllPhysicalSides() {
return mozilla::MakeInclusiveEnumeratedRange(eSideTop, eSideLeft);
@ -533,7 +533,7 @@ enum class SideBits {
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SideBits)
enum Corner {
enum Corner : uint8_t {
// This order is important!
eCornerTopLeft = 0,
eCornerTopRight = 1,

Просмотреть файл

@ -178,6 +178,13 @@ constexpr detail::EnumeratedRange<EnumType> MakeEnumeratedRange(EnumType aEnd) {
}
// Create a range to iterate from aBegin to aEnd, inclusive.
//
// NOTE: This internally constructs a value that is one past `aEnd`, so the
// enumeration needs to either have a fixed underlying type, or `aEnd + 1` must
// be inside the range of the enumeration, in order to not be undefined
// behavior.
//
// See bug 1614512.
template <typename EnumType>
constexpr detail::EnumeratedRange<EnumType> MakeInclusiveEnumeratedRange(
EnumType aBegin, EnumType aEnd) {