зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1719959 - Better Tag type choice, fixed corresponding test - r=emilio
On some systems, uint_fast8_t may be as big as size_t! So the `static_assert(sizeof(aIndex) < sizeof(size_t))` could fail there. The better test here is to check for the expected type (uint_fast8_t). Now, since uint_fast8_t can be bigger than 8 bits, we may as well choose it for variant sizes greater than 255, up to UINT_FAST8_MAX. (The added parentheses help clang-format distinguish '<' for tests vs for templates.) Differential Revision: https://phabricator.services.mozilla.com/D119574
This commit is contained in:
Родитель
3ba42a92ce
Коммит
81d28b5530
|
@ -112,11 +112,12 @@ struct VariantTag {
|
|||
static const size_t TypeCount = sizeof...(Ts);
|
||||
|
||||
public:
|
||||
using Type = std::conditional_t < TypeCount < 3, bool,
|
||||
std::conditional_t<TypeCount<(1 << 8), uint_fast8_t,
|
||||
size_t // stop caring past a certain
|
||||
// point :-)
|
||||
>>;
|
||||
using Type = std::conditional_t<
|
||||
(TypeCount <= 2), bool,
|
||||
std::conditional_t<(TypeCount <= size_t(UINT_FAST8_MAX)), uint_fast8_t,
|
||||
size_t // stop caring past a certain
|
||||
// point :-)
|
||||
>>;
|
||||
};
|
||||
|
||||
// TagHelper gets the given sentinel tag value for the given type T. This has to
|
||||
|
|
|
@ -806,7 +806,9 @@ static void testMatchingLambdaWithIndex() {
|
|||
// would be no way to distinguish how each lambda is actually invoked because
|
||||
// there is only one choice of call operator in each overload set.
|
||||
auto desc = [](auto aIndex, auto&& a) {
|
||||
static_assert(sizeof(aIndex) < sizeof(size_t), "Expected small index type");
|
||||
static_assert(
|
||||
std::is_same_v<decltype(aIndex), uint_fast8_t>,
|
||||
"Expected a uint_fast8_t index for a Variant with 3 alternatives");
|
||||
if constexpr (std::is_same_v<decltype(a), uint8_t&>) {
|
||||
MOZ_RELEASE_ASSERT(aIndex == 0);
|
||||
return RESULT(U8, ParamLREF, NA, a);
|
||||
|
|
Загрузка…
Ссылка в новой задаче