[llvm-commits] [llvm] r160882 - /llvm/trunk/include/llvm/ADT/SmallVector.h

Benjamin Kramer benny.kra at googlemail.com
Fri Jul 27 12:05:58 PDT 2012


Author: d0k
Date: Fri Jul 27 14:05:58 2012
New Revision: 160882

URL: http://llvm.org/viewvc/llvm-project?rev=160882&view=rev
Log:
SmallVector: Crank up verbosity of asserts per Chandler's request.

Also add assertions to validate the iterator in the insert method overloads.

Modified:
    llvm/trunk/include/llvm/ADT/SmallVector.h

Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=160882&r1=160881&r2=160882&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Fri Jul 27 14:05:58 2012
@@ -463,7 +463,9 @@
   }
 
   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 @@
   }
 
   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 @@
       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 @@
       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 @@
       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 @@
       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.





More information about the llvm-commits mailing list