Bug 873585 - Silence a vacuous-comparison-against-0 warning when compiling with gcc 4.5, at least. Also make IsSigned/IsUnsigned actually work on floating-point types. r=froydnj

--HG--
extra : rebase_source : 149695699ddb5cde3058a066785c2dc4c7c221e7
This commit is contained in:
Jeff Walden 2013-05-17 11:07:02 -07:00
parent 6d0be79332
commit 102c0879dc
2 changed files with 85 additions and 5 deletions

View File

@ -197,6 +197,21 @@ template<> struct IsPod<double> : TrueType {};
template<> struct IsPod<wchar_t> : TrueType {};
template<typename T> struct IsPod<T*> : TrueType {};
namespace detail {
template<typename T, bool = IsFloatingPoint<T>::value>
struct IsSignedHelper;
template<typename T>
struct IsSignedHelper<T, true> : TrueType {};
template<typename T>
struct IsSignedHelper<T, false>
: IntegralConstant<bool, IsArithmetic<T>::value && T(-1) < T(1)>
{};
} // namespace detail
/**
* IsSigned determines whether a type is a signed arithmetic type.
*
@ -209,10 +224,26 @@ template<typename T> struct IsPod<T*> : TrueType {};
* mozilla::IsSigned<float>::value is true.
*/
template<typename T>
struct IsSigned
: IntegralConstant<bool, IsArithmetic<T>::value && T(-1) < T(0)>
struct IsSigned : detail::IsSignedHelper<T> {};
namespace detail {
template<typename T, bool = IsFloatingPoint<T>::value>
struct IsUnsignedHelper;
template<typename T>
struct IsUnsignedHelper<T, true> : FalseType {};
template<typename T>
struct IsUnsignedHelper<T, false>
: IntegralConstant<bool,
IsArithmetic<T>::value &&
(IsSame<typename RemoveCV<T>::Type, bool>::value ||
T(1) < T(-1))>
{};
} // namespace detail
/**
* IsUnsigned determines whether a type is an unsigned arithmetic type.
*
@ -225,9 +256,7 @@ struct IsSigned
* mozilla::IsUnsigned<float>::value is false.
*/
template<typename T>
struct IsUnsigned
: IntegralConstant<bool, IsArithmetic<T>::value && T(0) < T(-1)>
{};
struct IsUnsigned : detail::IsUnsignedHelper<T> {};
/* 20.9.5 Type property queries [meta.unary.prop.query] */

View File

@ -8,6 +8,57 @@
using mozilla::IsBaseOf;
using mozilla::IsConvertible;
using mozilla::IsSigned;
using mozilla::IsUnsigned;
MOZ_STATIC_ASSERT(!IsSigned<bool>::value, "bool shouldn't be signed");
MOZ_STATIC_ASSERT(IsUnsigned<bool>::value, "bool should be unsigned");
MOZ_STATIC_ASSERT(!IsSigned<const bool>::value, "const bool shouldn't be signed");
MOZ_STATIC_ASSERT(IsUnsigned<const bool>::value, "const bool should be unsigned");
MOZ_STATIC_ASSERT(!IsSigned<volatile bool>::value, "volatile bool shouldn't be signed");
MOZ_STATIC_ASSERT(IsUnsigned<volatile bool>::value, "volatile bool should be unsigned");
MOZ_STATIC_ASSERT(!IsSigned<unsigned char>::value, "unsigned char shouldn't be signed");
MOZ_STATIC_ASSERT(IsUnsigned<unsigned char>::value, "unsigned char should be unsigned");
MOZ_STATIC_ASSERT(IsSigned<signed char>::value, "signed char should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<signed char>::value, "signed char shouldn't be unsigned");
MOZ_STATIC_ASSERT(!IsSigned<unsigned short>::value, "unsigned short shouldn't be signed");
MOZ_STATIC_ASSERT(IsUnsigned<unsigned short>::value, "unsigned short should be unsigned");
MOZ_STATIC_ASSERT(IsSigned<short>::value, "short should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<short>::value, "short shouldn't be unsigned");
MOZ_STATIC_ASSERT(!IsSigned<unsigned int>::value, "unsigned int shouldn't be signed");
MOZ_STATIC_ASSERT(IsUnsigned<unsigned int>::value, "unsigned int should be unsigned");
MOZ_STATIC_ASSERT(IsSigned<int>::value, "int should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<int>::value, "int shouldn't be unsigned");
MOZ_STATIC_ASSERT(!IsSigned<unsigned long>::value, "unsigned long shouldn't be signed");
MOZ_STATIC_ASSERT(IsUnsigned<unsigned long>::value, "unsigned long should be unsigned");
MOZ_STATIC_ASSERT(IsSigned<long>::value, "long should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<long>::value, "long shouldn't be unsigned");
MOZ_STATIC_ASSERT(IsSigned<float>::value, "float should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<float>::value, "float shouldn't be unsigned");
MOZ_STATIC_ASSERT(IsSigned<const float>::value, "const float should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<const float>::value, "const float shouldn't be unsigned");
MOZ_STATIC_ASSERT(IsSigned<double>::value, "double should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<double>::value, "double shouldn't be unsigned");
MOZ_STATIC_ASSERT(IsSigned<volatile double>::value, "volatile double should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<volatile double>::value, "volatile double shouldn't be unsigned");
MOZ_STATIC_ASSERT(IsSigned<long double>::value, "long double should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<long double>::value, "long double shouldn't be unsigned");
MOZ_STATIC_ASSERT(IsSigned<const volatile long double>::value,
"const volatile long double should be signed");
MOZ_STATIC_ASSERT(!IsUnsigned<const volatile long double>::value,
"const volatile long double shouldn't be unsigned");
namespace CPlusPlus11IsBaseOf {