OSDN Git Service

SmallVector: Crank up verbosity of asserts per Chandler's request.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 27 Jul 2012 19:05:58 +0000 (19:05 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 27 Jul 2012 19:05:58 +0000 (19:05 +0000)
Also add assertions to validate the iterator in the insert method overloads.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160882 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/SmallVector.h

index 9ca0898..2dbe708 100644 (file)
@@ -463,7 +463,9 @@ public:
   }
 
   iterator erase(iterator I) {
-    assert(I >= this->begin() && I < this->end() && "Iterator out of bounds");
+    assert(I >= this->begin() && "Iterator to erase is out of bounds.");
+    assert(I < this->end() && "Erasing at past-the-end iterator.");
+
     iterator N = I;
     // Shift all elts down one.
     this->move(I+1, this->end(), I);
@@ -473,8 +475,10 @@ public:
   }
 
   iterator erase(iterator S, iterator E) {
-    assert(S >= this->begin() && S <= E && E <= this->end() &&
-           "Iterator range out of bounds");
+    assert(S >= this->begin() && "Range to erase is out of bounds.");
+    assert(S <= E && "Trying to erase invalid range.");
+    assert(E <= this->end() && "Trying to erase past the end.");
+
     iterator N = S;
     // Shift all elts down.
     iterator I = this->move(E, this->end(), S);
@@ -491,6 +495,9 @@ public:
       return this->end()-1;
     }
 
+    assert(I >= this->begin() && "Insertion iterator is out of bounds.");
+    assert(I <= this->end() && "Inserting past the end of the vector.");
+
     if (this->EndX < this->CapacityX) {
     Retry:
       ::new ((void*) this->end()) T(::std::move(this->back()));
@@ -520,6 +527,9 @@ public:
       return this->end()-1;
     }
 
+    assert(I >= this->begin() && "Insertion iterator is out of bounds.");
+    assert(I <= this->end() && "Inserting past the end of the vector.");
+
     if (this->EndX < this->CapacityX) {
     Retry:
       ::new ((void*) this->end()) T(this->back());
@@ -551,6 +561,9 @@ public:
       return this->begin()+InsertElt;
     }
 
+    assert(I >= this->begin() && "Insertion iterator is out of bounds.");
+    assert(I <= this->end() && "Inserting past the end of the vector.");
+
     // Ensure there is enough space.
     reserve(static_cast<unsigned>(this->size() + NumToInsert));
 
@@ -599,6 +612,9 @@ public:
       return this->begin()+InsertElt;
     }
 
+    assert(I >= this->begin() && "Insertion iterator is out of bounds.");
+    assert(I <= this->end() && "Inserting past the end of the vector.");
+
     size_t NumToInsert = std::distance(From, To);
 
     // Ensure there is enough space.