Bug 1137583 - Fix for CV-qualified pointers; Added tests. r=waldo
authorGerald Squelart <from_mozilla@squelart.com>
Sun, 01 Mar 2015 18:08:00 +0100
changeset 246961 1c64893b5fddfdc39cef039eed22877146b4a5fe
parent 246960 b204778f4a7e209b5b6a94d3155750a7d7be14e7
child 246962 974ca22a87c646cbc94e915a4536630bbd9d0f4c
push id884
push userdburns@mozilla.com
push dateTue, 03 Mar 2015 15:29:12 +0000
reviewerswaldo
bugs1137583
milestone39.0a1
Bug 1137583 - Fix for CV-qualified pointers; Added tests. r=waldo
mfbt/TypeTraits.h
mfbt/tests/TestTypeTraits.cpp
--- a/mfbt/TypeTraits.h
+++ b/mfbt/TypeTraits.h
@@ -157,31 +157,44 @@ struct IsArrayHelper<T[]> : TrueType {};
  * mozilla::IsArray<int>::value is false;
  * mozilla::IsArray<int[]>::value is true;
  * mozilla::IsArray<int[5]>::value is true.
  */
 template<typename T>
 struct IsArray : detail::IsArrayHelper<typename RemoveCV<T>::Type>
 {};
 
+namespace detail {
+
+template<typename T>
+struct IsPointerHelper : FalseType {};
+
+template<typename T>
+struct IsPointerHelper<T*> : TrueType {};
+
+} // namespace detail
+
 /**
- * IsPointer determines whether a type is a pointer type (but not a pointer-to-
- * member type).
+ * IsPointer determines whether a type is a possibly-CV-qualified pointer type
+ * (but not a pointer-to-member type).
  *
  * mozilla::IsPointer<struct S*>::value is true;
+ * mozilla::IsPointer<int*>::value is true;
  * mozilla::IsPointer<int**>::value is true;
+ * mozilla::IsPointer<const int*>::value is true;
+ * mozilla::IsPointer<int* const>::value is true;
+ * mozilla::IsPointer<int* volatile>::value is true;
  * mozilla::IsPointer<void (*)(void)>::value is true;
  * mozilla::IsPointer<int>::value is false;
  * mozilla::IsPointer<struct S>::value is false.
+ * mozilla::IsPointer<int(struct S::*)>::value is false
  */
 template<typename T>
-struct IsPointer : FalseType {};
-
-template<typename T>
-struct IsPointer<T*> : TrueType {};
+struct IsPointer : detail::IsPointerHelper<typename RemoveCV<T>::Type>
+{};
 
 /**
  * IsLvalueReference determines whether a type is an lvalue reference.
  *
  * mozilla::IsLvalueReference<struct S*>::value is false;
  * mozilla::IsLvalueReference<int**>::value is false;
  * mozilla::IsLvalueReference<void (*)(void)>::value is false;
  * mozilla::IsLvalueReference<int>::value is false;
--- a/mfbt/tests/TestTypeTraits.cpp
+++ b/mfbt/tests/TestTypeTraits.cpp
@@ -9,32 +9,57 @@
 
 using mozilla::AddLvalueReference;
 using mozilla::IsArray;
 using mozilla::IsBaseOf;
 using mozilla::IsClass;
 using mozilla::IsConvertible;
 using mozilla::IsEmpty;
 using mozilla::IsLvalueReference;
+using mozilla::IsPointer;
 using mozilla::IsReference;
 using mozilla::IsRvalueReference;
 using mozilla::IsSame;
 using mozilla::IsSigned;
 using mozilla::IsUnsigned;
 using mozilla::MakeSigned;
 using mozilla::MakeUnsigned;
 using mozilla::RemoveExtent;
 
 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(!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");
+static_assert(IsPointer<bool* const volatile>::value,
+              "bool* const volatile is a pointer");
+static_assert(IsPointer<bool**>::value,
+              "bool** is a pointer");
+static_assert(IsPointer<void (*)(void)>::value,
+              "void (*)(void) is a pointer");
+struct IsPointerTest { bool m; void f(); };
+static_assert(!IsPointer<IsPointerTest>::value,
+              "IsPointerTest not a pointer");
+static_assert(IsPointer<IsPointerTest*>::value,
+              "IsPointerTest* is a pointer");
+static_assert(!IsPointer<bool(IsPointerTest::*)>::value,
+              "bool(IsPointerTest::*) not a pointer");
+static_assert(!IsPointer<void(IsPointerTest::*)(void)>::value,
+              "void(IsPointerTest::*)(void) not a pointer");
+
 static_assert(!IsLvalueReference<bool>::value,
               "bool not an lvalue reference");
 static_assert(!IsLvalueReference<bool*>::value,
               "bool* not an lvalue reference");
 static_assert(IsLvalueReference<bool&>::value,
               "bool& is an lvalue reference");
 static_assert(!IsLvalueReference<bool&&>::value,
               "bool&& not an lvalue reference");