Bug 1400307 - handle char32_t in TypeTraits.h; r?froydnj draft
authorTom Tromey <tom@tromey.com>
Fri, 15 Sep 2017 13:01:11 -0600
changeset 665619 d438d0ad965d8d3b9fd7a600a6ff0233716ab796
parent 665508 0e14317d2f6c454e86549fe84d6067e1745a76c5
child 731835 232a133848bf600a31f390ef608cbb120e2a69e6
push id80122
push userbmo:ttromey@mozilla.com
push dateFri, 15 Sep 2017 19:05:00 +0000
reviewersfroydnj
bugs1400307
milestone57.0a1
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
mfbt/TypeTraits.h
mfbt/tests/TestTypeTraits.cpp
--- 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;
+private:
+  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");