This is with Visual Studio 2012.
static void func(
...,
const std::vector<std::string> &opt_extra_args_strs,
...)
{
for (const std::string &arg_str : opt_extra_args_strs) {
... body does not modify opt_extra_args_strs
for (size_t a_ix = 0; a_ix < opt_extra_args_strs.size(); a_ix++) {
const std::string &arg_str = opt_extra_args_strs[a_ix];
}
I do not change the vector at all in the body of the loop, and in fact the statement occurs before the first iteration. The vector looks correct in the debugger, but I don’t know enough about the STL to look for corruption. Inside the STL, an assertion error occurs from:
void _Compat(const _Myiter& _Right) const {
if (this->_Getcont() == 0
...) {
_DEBUG_ERROR("vector iterators incompatible");
with this->_Getcont()equal to NULL, because ( _Myproxyequal to NULL in _Iterator_base12). Call stack:
msvcp110d.dll!std::_Debug_message(const wchar_t * message, const wchar_t * file, unsigned int line) Line 15 C++
Main.exe!std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >::_Compat(const std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > > & _Right)
Main.exe!std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >::operator==(const std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > > & _Right)
Main.exe!std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >::operator!=(const std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > > & _Right)
Main.exe!run_test(..., const std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > & opt_extra_args_strs)
...
I suspect that the code creating the vector somehow screwed it, but I'm not sure. It’s also difficult for me to write a simpler reproducing one, but the program must be completely deterministic (single-threaded, not random variables, always states).
, "vector iterator + offset out of range" ( )
template <typename T>
class Elsewhere {
virtual void earlier(
....
std::vector<T> &v) const
{
v.emplace_back();
T &val = to[to.size() - 1];
... mutates val.
T = std::string (, ).
, STL this->_Getcont() == 0, , . , _Getcont() 0 Vector_const_iterator?
template <typename T>
struct type {
T m_value;
operator const T &() const {
return value();
}
const T &value() const {
return m_value;
}
};
type<std::vector<std::string>> &t = ... method call that returns ref to it;
... t gets set
func(t);