Add asserts to SmallVector so that calls to front() and back() only succeed
authorRichard Trieu <rtrieu@google.com>
Thu, 24 Jan 2013 04:29:24 +0000 (04:29 +0000)
committerRichard Trieu <rtrieu@google.com>
Thu, 24 Jan 2013 04:29:24 +0000 (04:29 +0000)
if the vector is not empty.  This will ensure that calls to these functions
will reference elements in the vector.

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

include/llvm/ADT/SmallVector.h

index 951e5741ffba7150dca14858f478d61528ed9a6c..9167f872185d94bc4dd54bee7c84616f2a2d98ba 100644 (file)
@@ -145,16 +145,20 @@ public:
   }
 
   reference front() {
+    assert(!empty());
     return begin()[0];
   }
   const_reference front() const {
+    assert(!empty());
     return begin()[0];
   }
 
   reference back() {
+    assert(!empty());
     return end()[-1];
   }
   const_reference back() const {
+    assert(!empty());
     return end()[-1];
   }
 };