Add some negative (and positive) static_assert checks for ArrayRef-of-pointer convers...
authorDavid Blaikie <dblaikie@gmail.com>
Sun, 31 Aug 2014 01:33:41 +0000 (01:33 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Sun, 31 Aug 2014 01:33:41 +0000 (01:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216830 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/ADT/ArrayRefTest.cpp

index 649936714f3afdb5e1cf864a45544535529b93bb..f9c98a563fa3cbb39035cac2f034e82b31f11b3f 100644 (file)
 #include "gtest/gtest.h"
 using namespace llvm;
 
+// Check that the ArrayRef-of-pointer converting constructor only allows adding
+// cv qualifiers (not removing them, or otherwise changing the type)
+static_assert(
+    std::is_convertible<ArrayRef<int *>, ArrayRef<const int *>>::value,
+    "Adding const");
+static_assert(
+    std::is_convertible<ArrayRef<int *>, ArrayRef<volatile int *>>::value,
+    "Adding volatile");
+static_assert(!std::is_convertible<ArrayRef<int *>, ArrayRef<float *>>::value,
+              "Changing pointer of one type to a pointer of another");
+static_assert(
+    !std::is_convertible<ArrayRef<const int *>, ArrayRef<int *>>::value,
+    "Removing const");
+static_assert(
+    !std::is_convertible<ArrayRef<volatile int *>, ArrayRef<int *>>::value,
+    "Removing volatile");
+
 namespace llvm {
 
 TEST(ArrayRefTest, AllocatorCopy) {