Bug 1400307 - handle char32_t in TypeTraits.h; r?froydnj
This adds a couple of missing char32_t specializations to TypeTraits.h,
and adds a few extra type traits tests besides.
MozReview-Commit-ID: 7aIJbZ2Ppka
--- a/mfbt/TypeTraits.h
+++ b/mfbt/TypeTraits.h
@@ -94,16 +94,17 @@ template<> struct IsIntegralHelper<int>
template<> struct IsIntegralHelper<unsigned int> : TrueType {};
template<> struct IsIntegralHelper<long> : TrueType {};
template<> struct IsIntegralHelper<unsigned long> : TrueType {};
template<> struct IsIntegralHelper<long long> : TrueType {};
template<> struct IsIntegralHelper<unsigned long long> : TrueType {};
template<> struct IsIntegralHelper<bool> : TrueType {};
template<> struct IsIntegralHelper<wchar_t> : TrueType {};
template<> struct IsIntegralHelper<char16_t> : TrueType {};
+template<> struct IsIntegralHelper<char32_t> : TrueType {};
} /* namespace detail */
/**
* IsIntegral determines whether a type is an integral type.
*
* mozilla::IsIntegral<int>::value is true;
* mozilla::IsIntegral<unsigned short>::value is true;
@@ -435,16 +436,17 @@ template<> struct IsPod<long>
template<> struct IsPod<unsigned long> : TrueType {};
template<> struct IsPod<long long> : TrueType {};
template<> struct IsPod<unsigned long long> : TrueType {};
template<> struct IsPod<bool> : TrueType {};
template<> struct IsPod<float> : TrueType {};
template<> struct IsPod<double> : TrueType {};
template<> struct IsPod<wchar_t> : TrueType {};
template<> struct IsPod<char16_t> : TrueType {};
+template<> struct IsPod<char32_t> : TrueType {};
template<typename T> struct IsPod<T*> : TrueType {};
namespace detail {
// __is_empty is a supported extension across all of our supported compilers:
// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html
// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits
// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx
--- a/mfbt/tests/TestTypeTraits.cpp
+++ b/mfbt/tests/TestTypeTraits.cpp
@@ -21,17 +21,19 @@ using mozilla::DeclVal;
using mozilla::IsFunction;
using mozilla::IsArray;
using mozilla::IsBaseOf;
using mozilla::IsClass;
using mozilla::IsConvertible;
using mozilla::IsDefaultConstructible;
using mozilla::IsDestructible;
using mozilla::IsEmpty;
+using mozilla::IsIntegral;
using mozilla::IsLvalueReference;
+using mozilla::IsPod;
using mozilla::IsPointer;
using mozilla::IsReference;
using mozilla::IsRvalueReference;
using mozilla::IsSame;
using mozilla::IsSigned;
using mozilla::IsUnsigned;
using mozilla::MakeSigned;
using mozilla::MakeUnsigned;
@@ -47,16 +49,49 @@ static_assert(!IsFunction<void(*)(int)>:
static_assert(!IsArray<bool>::value,
"bool not an array");
static_assert(IsArray<bool[]>::value,
"bool[] is an array");
static_assert(IsArray<bool[5]>::value,
"bool[5] is an array");
+static_assert(IsIntegral<char16_t>::value,
+ "char16_t is integral");
+static_assert(IsIntegral<char32_t>::value,
+ "char32_t is integral");
+static_assert(!IsIntegral<char&>::value,
+ "char& is not integral");
+static_assert(!IsIntegral<double>::value,
+ "double is not integral");
+
+static_assert(IsPod<bool>::value,
+ "bool is pod");
+static_assert(IsPod<char16_t>::value,
+ "char16_t is pod");
+static_assert(IsPod<char32_t>::value,
+ "char32_t is pod");
+struct YepItsAPod { int x; };
+static_assert(!IsPod<YepItsAPod>::value,
+ "pod struct is pod");
+struct NopeItsNotAPod {
+ int x;
+ protected:
+ int y;
+};
+static_assert(!IsPod<NopeItsNotAPod>::value,
+ "non-standard-layout struct is not pod");
+struct NopeStillNotAPod {
+ NopeStillNotAPod() : x(7) { }
+ int x;
+};
+static_assert(!IsPod<NopeStillNotAPod>::value,
+ "struct with constructor is not pod");
+
+
static_assert(!IsPointer<bool>::value,
"bool not a pointer");
static_assert(IsPointer<bool*>::value,
"bool* is a pointer");
static_assert(IsPointer<bool* const>::value,
"bool* const is a pointer");
static_assert(IsPointer<bool* volatile>::value,
"bool* volatile is a pointer");