I'm using cppcheck built from source.
The following code gives error: [test.cpp:15] -> [test.cpp:17]: (error) Iterator 'it' used after element has been erased.
namespace cereal { class InputArchive { private: template <class T, traits::EnableIf<traits::has_member_serialize<T, ArchiveType>::value> = traits::sfinae> inline }; } void Do_Work() { std::vector<std::string> m_background_task_queue; std::vector<std::string>::iterator it = m_background_task_queue.begin(); while (it != m_background_task_queue.end()) { it = m_background_task_queue.erase(it); } }
The following does NOT give any error message (iterator type changed to auto):
namespace cereal { class InputArchive { private: template <class T, traits::EnableIf<traits::has_member_serialize<T, ArchiveType>::value> = traits::sfinae> inline }; } void Do_Work() { std::vector<std::string> m_background_task_queue; auto it = m_background_task_queue.begin(); while (it != m_background_task_queue.end()) { it = m_background_task_queue.erase(it); } }
The following also does not give any error message:
void Do_Work() { std::vector<std::string> m_background_task_queue; std::vector<std::string>::iterator it = m_background_task_queue.begin(); while (it != m_background_task_queue.end()) { it = m_background_task_queue.erase(it) ; } }
This gives an error message:
void Do_Work() { std::vector<std::string> m_background_task_queue; std::vector<std::string>::iterator it = m_background_task_queue.begin(); while (it != m_background_task_queue.end()) { it = m_background_task_queue.erase(it) - 1; } }
Neither of the two cases reproduces with 2.3.
Log in to post a comment.
I'm using cppcheck built from source.
The following code gives error: [test.cpp:15] -> [test.cpp:17]: (error) Iterator 'it' used after element has been erased.
The following does NOT give any error message (iterator type changed to auto):
The following also does not give any error message:
This gives an error message:
Last edit: Erik 2018-08-30
Neither of the two cases reproduces with 2.3.