diff --git a/mfbt/TypeTraits.h b/mfbt/TypeTraits.h index 968d44a410..df21a71343 100644 --- a/mfbt/TypeTraits.h +++ b/mfbt/TypeTraits.h @@ -637,12 +637,31 @@ public: * For obscure reasons, you can't use IsConvertible when the types being tested * are related through private inheritance, and you'll get a compile error if * you try. Just don't do it! + * + * Note - we need special handling for void, which ConvertibleTester doesn't + * handle. The void handling here doesn't handle const/volatile void correctly, + * which could be easily fixed if the need arises. */ template struct IsConvertible : IntegralConstant::value> {}; +template +struct IsConvertible + : IntegralConstant::value> +{}; + +template +struct IsConvertible + : IntegralConstant::value> +{}; + +template<> +struct IsConvertible + : TrueType +{}; + /* 20.9.7 Transformations between types [meta.trans] */ /* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ diff --git a/mfbt/tests/TestTypeTraits.cpp b/mfbt/tests/TestTypeTraits.cpp index 8fb053c530..dfc44a3177 100644 --- a/mfbt/tests/TestTypeTraits.cpp +++ b/mfbt/tests/TestTypeTraits.cpp @@ -354,6 +354,10 @@ TestIsConvertible() static_assert((!IsConvertible::value), "A and D are unrelated"); + static_assert(IsConvertible::value, "void is void"); + static_assert(!IsConvertible::value, "A shouldn't convert to void"); + static_assert(!IsConvertible::value, "void shouldn't convert to B"); + // These cases seem to require C++11 support to properly implement them, so // for now just disable them. //static_assert((!IsConvertible::value),