[docs] Fixed a typo in Atomics.rst
[oota-llvm.git] / unittests / ADT / ArrayRefTest.cpp
index a25f932d4ce683d2d7951360307155a1ceb6cad7..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) {
@@ -63,4 +80,14 @@ TEST(ArrayRefTest, EmptyEquals) {
   EXPECT_TRUE(ArrayRef<unsigned>() == ArrayRef<unsigned>());
 }
 
+TEST(ArrayRefTest, ConstConvert) {
+  int buf[4];
+  for (int i = 0; i < 4; ++i)
+    buf[i] = i;
+
+  static int *A[] = {&buf[0], &buf[1], &buf[2], &buf[3]};
+  ArrayRef<const int *> a((ArrayRef<int *>(A)));
+  a = ArrayRef<int *>(A);
+}
+
 } // end anonymous namespace