Index: include/vector =================================================================== --- include/vector +++ include/vector @@ -1905,9 +1905,11 @@ pointer __old_last = this->__end_; for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) { + __RAII_IncreaseAnnotator __annotator(*this); __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); ++this->__end_; + __annotator.__done(); } __split_buffer __v(__a); if (__first != __last) Index: test/std/containers/sequences/vector/asan.pass.cpp =================================================================== --- test/std/containers/sequences/vector/asan.pass.cpp +++ test/std/containers/sequences/vector/asan.pass.cpp @@ -21,6 +21,20 @@ #ifndef _LIBCPP_HAS_NO_ASAN extern "C" void __asan_set_error_exit_code(int); +// This is a Toy iterator that ensures that the vector::insert +// specialization for non-forward_iterators is taken. +class MyInputIter : public std::iterator { +public: + MyInputIter(int* ptr) : ptr_(ptr) {} + friend bool operator!=(const MyInputIter& i1, const MyInputIter& i2) { + return i1.ptr_ != i2.ptr_; + } + MyInputIter& operator++() { ++ptr_; return *this; } + int operator*() const { return *ptr_; } +private: + int* ptr_; +}; + int main() { #if __cplusplus >= 201103L @@ -33,7 +47,17 @@ T foo = c[c.size()]; // bad, but not caught by ASAN } #endif - + + { + // Sould not trigger ASan. + std::vector v; + v.reserve(1); + int i = 42; + v.insert(v.begin(), MyInputIter(&i), MyInputIter(&i + 1)); + assert(v[0] == 42); + assert(is_contiguous_container_asan_correct(v)); + } + __asan_set_error_exit_code(0); { typedef int T;