fix leak in a test, make the sanitizer bot green
[oota-llvm.git] / unittests / ADT / TinyPtrVectorTest.cpp
index a4f92ffbe38372f815be2b800ba418a007ca2516..294dfac0c6336e7b8570324a67af885ed23482ae 100644 (file)
@@ -36,7 +36,7 @@ template <typename VectorT>
 class TinyPtrVectorTest : public testing::Test {
 protected:
   typedef typename VectorT::value_type PtrT;
-  typedef typename remove_pointer<PtrT>::type ValueT;
+  typedef typename std::remove_pointer<PtrT>::type ValueT;
 
   VectorT V;
   VectorT V2;
@@ -72,9 +72,9 @@ protected:
     EXPECT_EQ(Values.size(), V.size());
     for (size_t i = 0, e = Values.size(); i != e; ++i) {
       EXPECT_EQ(Values[i], V[i]);
-      EXPECT_EQ(Values[i], *llvm::next(V.begin(), i));
+      EXPECT_EQ(Values[i], *std::next(V.begin(), i));
     }
-    EXPECT_EQ(V.end(), llvm::next(V.begin(), Values.size()));
+    EXPECT_EQ(V.end(), std::next(V.begin(), Values.size()));
   }
 };
 
@@ -157,170 +157,136 @@ TYPED_TEST(TinyPtrVectorTest, CopyAndMoveCtorTest) {
   this->expectValues(Copy2, this->testArray(42));
   this->expectValues(this->V2, this->testArray(0));
 
-#if LLVM_HAS_RVALUE_REFERENCES
   TypeParam Move(std::move(Copy2));
   this->expectValues(Move, this->testArray(42));
   this->expectValues(Copy2, this->testArray(0));
-#endif
 }
 
 TYPED_TEST(TinyPtrVectorTest, CopyAndMoveTest) {
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(0));
   this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(0));
-#endif
 
   this->setVectors(this->testArray(1), this->testArray(0));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(0));
   this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(1), this->testArray(0));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(0));
-#endif
 
   this->setVectors(this->testArray(2), this->testArray(0));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(0));
   this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(2), this->testArray(0));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(0));
-#endif
 
   this->setVectors(this->testArray(42), this->testArray(0));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(0));
   this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(42), this->testArray(0));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(0));
-#endif
 
   this->setVectors(this->testArray(0), this->testArray(1));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(1));
   this->expectValues(this->V2, this->testArray(1));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(0), this->testArray(1));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(1));
-#endif
 
   this->setVectors(this->testArray(0), this->testArray(2));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(2));
   this->expectValues(this->V2, this->testArray(2));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(0), this->testArray(2));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(2));
-#endif
 
   this->setVectors(this->testArray(0), this->testArray(42));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(42));
   this->expectValues(this->V2, this->testArray(42));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(0), this->testArray(42));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(42));
-#endif
 
   this->setVectors(this->testArray(1), this->testArray(1));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(1));
   this->expectValues(this->V2, this->testArray(1));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(1));
-#endif
 
   this->setVectors(this->testArray(1), this->testArray(2));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(2));
   this->expectValues(this->V2, this->testArray(2));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(1), this->testArray(2));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(2));
-#endif
 
   this->setVectors(this->testArray(1), this->testArray(42));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(42));
   this->expectValues(this->V2, this->testArray(42));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(1), this->testArray(42));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(42));
-#endif
 
   this->setVectors(this->testArray(2), this->testArray(1));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(1));
   this->expectValues(this->V2, this->testArray(1));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(2), this->testArray(1));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(1));
-#endif
 
   this->setVectors(this->testArray(2), this->testArray(2));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(2));
   this->expectValues(this->V2, this->testArray(2));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(2), this->testArray(2));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(2));
-#endif
 
   this->setVectors(this->testArray(2), this->testArray(42));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(42));
   this->expectValues(this->V2, this->testArray(42));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(2), this->testArray(42));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(42));
-#endif
 
   this->setVectors(this->testArray(42), this->testArray(1));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(1));
   this->expectValues(this->V2, this->testArray(1));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(42), this->testArray(1));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(1));
-#endif
 
   this->setVectors(this->testArray(42), this->testArray(2));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(2));
   this->expectValues(this->V2, this->testArray(2));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(42), this->testArray(2));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(2));
-#endif
 
   this->setVectors(this->testArray(42), this->testArray(42));
   this->V = this->V2;
   this->expectValues(this->V, this->testArray(42));
   this->expectValues(this->V2, this->testArray(42));
-#if LLVM_HAS_RVALUE_REFERENCES
   this->setVectors(this->testArray(42), this->testArray(42));
   this->V = std::move(this->V2);
   this->expectValues(this->V, this->testArray(42));
-#endif
 }
 
 TYPED_TEST(TinyPtrVectorTest, EraseTest) {
@@ -334,17 +300,17 @@ TYPED_TEST(TinyPtrVectorTest, EraseTest) {
   this->V.erase(this->V.begin());
   this->TestPtrs.erase(this->TestPtrs.begin());
   this->expectValues(this->V, this->testArray(41));
-  this->V.erase(llvm::next(this->V.begin(), 1));
-  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 1));
+  this->V.erase(std::next(this->V.begin(), 1));
+  this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 1));
   this->expectValues(this->V, this->testArray(40));
-  this->V.erase(llvm::next(this->V.begin(), 2));
-  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 2));
+  this->V.erase(std::next(this->V.begin(), 2));
+  this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 2));
   this->expectValues(this->V, this->testArray(39));
-  this->V.erase(llvm::next(this->V.begin(), 5));
-  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 5));
+  this->V.erase(std::next(this->V.begin(), 5));
+  this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 5));
   this->expectValues(this->V, this->testArray(38));
-  this->V.erase(llvm::next(this->V.begin(), 13));
-  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 13));
+  this->V.erase(std::next(this->V.begin(), 13));
+  this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 13));
   this->expectValues(this->V, this->testArray(37));
 
   typename TypeParam::iterator I = this->V.begin();
@@ -366,27 +332,27 @@ TYPED_TEST(TinyPtrVectorTest, EraseRangeTest) {
 
   this->appendValues(this->V, this->testArray(42));
   this->expectValues(this->V, this->testArray(42));
-  this->V.erase(this->V.begin(), llvm::next(this->V.begin(), 1));
+  this->V.erase(this->V.begin(), std::next(this->V.begin(), 1));
   this->TestPtrs.erase(this->TestPtrs.begin(),
-                       llvm::next(this->TestPtrs.begin(), 1));
+                       std::next(this->TestPtrs.begin(), 1));
   this->expectValues(this->V, this->testArray(41));
-  this->V.erase(llvm::next(this->V.begin(), 1), llvm::next(this->V.begin(), 2));
-  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 1),
-                       llvm::next(this->TestPtrs.begin(), 2));
+  this->V.erase(std::next(this->V.begin(), 1), std::next(this->V.begin(), 2));
+  this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 1),
+                       std::next(this->TestPtrs.begin(), 2));
   this->expectValues(this->V, this->testArray(40));
-  this->V.erase(llvm::next(this->V.begin(), 2), llvm::next(this->V.begin(), 4));
-  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 2),
-                       llvm::next(this->TestPtrs.begin(), 4));
+  this->V.erase(std::next(this->V.begin(), 2), std::next(this->V.begin(), 4));
+  this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 2),
+                       std::next(this->TestPtrs.begin(), 4));
   this->expectValues(this->V, this->testArray(38));
-  this->V.erase(llvm::next(this->V.begin(), 5), llvm::next(this->V.begin(), 10));
-  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 5),
-                       llvm::next(this->TestPtrs.begin(), 10));
+  this->V.erase(std::next(this->V.begin(), 5), std::next(this->V.begin(), 10));
+  this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 5),
+                       std::next(this->TestPtrs.begin(), 10));
   this->expectValues(this->V, this->testArray(33));
-  this->V.erase(llvm::next(this->V.begin(), 13), llvm::next(this->V.begin(), 26));
-  this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 13),
-                       llvm::next(this->TestPtrs.begin(), 26));
+  this->V.erase(std::next(this->V.begin(), 13), std::next(this->V.begin(), 26));
+  this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 13),
+                       std::next(this->TestPtrs.begin(), 26));
   this->expectValues(this->V, this->testArray(20));
-  this->V.erase(llvm::next(this->V.begin(), 7), this->V.end());
+  this->V.erase(std::next(this->V.begin(), 7), this->V.end());
   this->expectValues(this->V, this->testArray(7));
   this->V.erase(this->V.begin(), this->V.end());
   this->expectValues(this->V, this->testArray(0));
@@ -403,8 +369,8 @@ TYPED_TEST(TinyPtrVectorTest, Insert) {
   this->V.insert(this->V.begin(), this->TestPtrs[42]);
   this->TestPtrs.insert(this->TestPtrs.begin(), this->TestPtrs[42]);
   this->expectValues(this->V, this->testArray(6));
-  this->V.insert(llvm::next(this->V.begin(), 3), this->TestPtrs[43]);
-  this->TestPtrs.insert(llvm::next(this->TestPtrs.begin(), 3),
+  this->V.insert(std::next(this->V.begin(), 3), this->TestPtrs[43]);
+  this->TestPtrs.insert(std::next(this->TestPtrs.begin(), 3),
                         this->TestPtrs[43]);
   this->expectValues(this->V, this->testArray(7));
 }
@@ -418,31 +384,78 @@ TYPED_TEST(TinyPtrVectorTest, InsertRange) {
   this->V.insert(this->V.end(), this->TestPtrs.end(), this->TestPtrs.end());
   this->expectValues(this->V, this->testArray(0));
   this->V.insert(this->V.end(), this->TestPtrs.begin(),
-                 llvm::next(this->TestPtrs.begin()));
+                 std::next(this->TestPtrs.begin()));
   this->expectValues(this->V, this->testArray(1));
   this->V.clear();
   this->V.insert(this->V.end(), this->TestPtrs.begin(),
-                 llvm::next(this->TestPtrs.begin(), 2));
+                 std::next(this->TestPtrs.begin(), 2));
   this->expectValues(this->V, this->testArray(2));
   this->V.clear();
   this->V.insert(this->V.end(), this->TestPtrs.begin(),
-                 llvm::next(this->TestPtrs.begin(), 42));
+                 std::next(this->TestPtrs.begin(), 42));
   this->expectValues(this->V, this->testArray(42));
   this->V.clear();
   this->V.insert(this->V.end(),
-                 llvm::next(this->TestPtrs.begin(), 5),
-                 llvm::next(this->TestPtrs.begin(), 13));
+                 std::next(this->TestPtrs.begin(), 5),
+                 std::next(this->TestPtrs.begin(), 13));
   this->V.insert(this->V.begin(),
-                 llvm::next(this->TestPtrs.begin(), 0),
-                 llvm::next(this->TestPtrs.begin(), 3));
-  this->V.insert(llvm::next(this->V.begin(), 2),
-                 llvm::next(this->TestPtrs.begin(), 2),
-                 llvm::next(this->TestPtrs.begin(), 4));
-  this->V.erase(llvm::next(this->V.begin(), 4));
-  this->V.insert(llvm::next(this->V.begin(), 4),
-                 llvm::next(this->TestPtrs.begin(), 4),
-                 llvm::next(this->TestPtrs.begin(), 5));
+                 std::next(this->TestPtrs.begin(), 0),
+                 std::next(this->TestPtrs.begin(), 3));
+  this->V.insert(std::next(this->V.begin(), 2),
+                 std::next(this->TestPtrs.begin(), 2),
+                 std::next(this->TestPtrs.begin(), 4));
+  this->V.erase(std::next(this->V.begin(), 4));
+  this->V.insert(std::next(this->V.begin(), 4),
+                 std::next(this->TestPtrs.begin(), 4),
+                 std::next(this->TestPtrs.begin(), 5));
   this->expectValues(this->V, this->testArray(13));
 }
 
 }
+
+TEST(TinyPtrVectorTest, SingleEltCtorTest) {
+  int v = 55;
+  TinyPtrVector<int *> V(&v);
+
+  EXPECT_TRUE(V.size() == 1);
+  EXPECT_FALSE(V.empty());
+  EXPECT_TRUE(V.front() == &v);
+}
+
+TEST(TinyPtrVectorTest, ArrayRefCtorTest) {
+  int data_array[128];
+  std::vector<int *> data;
+
+  for (unsigned i = 0, e = 128; i != e; ++i) {
+    data_array[i] = 324 - int(i);
+    data.push_back(&data_array[i]);
+  }
+
+  TinyPtrVector<int *> V(data);
+  EXPECT_TRUE(V.size() == 128);
+  EXPECT_FALSE(V.empty());
+  for (unsigned i = 0, e = 128; i != e; ++i) {
+    EXPECT_TRUE(V[i] == data[i]);
+  }
+}
+
+TEST(TinyPtrVectorTest, MutableArrayRefTest) {
+  int data_array[128];
+  std::vector<int *> data;
+
+  for (unsigned i = 0, e = 128; i != e; ++i) {
+    data_array[i] = 324 - int(i);
+    data.push_back(&data_array[i]);
+  }
+
+  TinyPtrVector<int *> V(data);
+  EXPECT_TRUE(V.size() == 128);
+  EXPECT_FALSE(V.empty());
+
+  MutableArrayRef<int *> mut_array = V;
+  for (unsigned i = 0, e = 128; i != e; ++i) {
+    EXPECT_TRUE(mut_array[i] == data[i]);
+    mut_array[i] = 324 + mut_array[i];
+    EXPECT_TRUE(mut_array[i] == (324 + data[i]));
+  }
+}