Hello,
I have a problem with vector destructor if I use it with range based for loop.
Sample code to reproduce this issue:
#include <vector> class foo { public: void bar(const std::vector<int>& ints) { std::vector<int> items; #if 1 for (const auto& i : ints) { #else for (size_t j = 0; j < ints.size(); ++j) { int i = ints[j]; #endif items.push_back(i+5); } } }; int main() { std::vector<int> ints{ 1,2,5,7,9,0 }; foo f; f.bar(ints); return 0; }
The call stack:
> VectorCrash.exe!std::_Container_base12::_Orphan_all() Line 223 C++
VectorCrash.exe!std::_Vector_alloc<std::_Vec_base_types<int, std::allocator<int> > >::_Orphan_all() Line 614 C++
VectorCrash.exe!std::vector<int, std::allocator<int> >::_Tidy() Line 1640 C++
VectorCrash.exe!std::vector<int, std::allocator<int> >::~vector() Line 977 C++
VectorCrash.exe!main() Line 36 C++
VectorCrash.exe!invoke_main() Line 64 C++
It crashes in:
inline void _Container_base12::_Orphan_all()
function in xutility header, when _ITERATOR_DEBUG_LEVEL == 2, also in Debug configuration.
My compiler: Intel® Parallel Studio XE 2017 Update 1 Composer Edition for C++ Windows* Integration for Microsoft* Visual Studio* 2015, Version 17.0.71.14
It works fine with Microsoft C++ compiler.
Best regards
Przemek