diff --git a/mfbt/Variant.h b/mfbt/Variant.h index 27d79de372095..41bb002092188 100644 --- a/mfbt/Variant.h +++ b/mfbt/Variant.h @@ -24,6 +24,34 @@ class Variant; namespace detail { +template +struct FirstTypeIsInRest; + +template +struct FirstTypeIsInRest : FalseType {}; + +template +struct FirstTypeIsInRest +{ + static constexpr bool value = + IsSame::value || + FirstTypeIsInRest::value; +}; + +template +struct TypesAreDistinct; + +template <> +struct TypesAreDistinct<> : TrueType { }; + +template +struct TypesAreDistinct +{ + static constexpr bool value = + !FirstTypeIsInRest::value && + TypesAreDistinct::value; +}; + // MaxSizeOf computes the maximum sizeof(T) for each T in Ts. template @@ -428,6 +456,7 @@ struct AsVariantTemporary template class MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS Variant { + static_assert(detail::TypesAreDistinct::value, "Variant with duplicate types is not supported"); using Tag = typename detail::VariantTag::Type; using Impl = detail::VariantImplementation; using RawData = AlignedStorage::size>;