vector::erase returns incompatible iterator in debug build - by BartoszMilewski

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 545013 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 3/26/2010 2:20:42 PM
Access Restriction Public


std::vector<int> v;
auto it = v.erase(v.begin(), v.begin() + 1);
bool b = (it == v.begin());
Assertion "vector iterators incompatible" fails in the last line. This is because the iterator returned by erase has null pointer to the owning container. 
Sign in to post a comment.
Posted by Roy Fejgin on 6/26/2012 at 5:49 PM
This was fixed in VS2010 SP1. See release notes:
Posted by Stephan [MSFT] on 6/22/2010 at 3:10 PM

Thanks again for reporting this bug. We've fixed it, and the fix will be available in VC11.

As always, if you have any further questions, feel free to E-mail me at .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Stephan [MSFT] on 4/5/2010 at 4:28 PM
I suggest synthesizing the return value yourself:

C:\Temp>type purr.cpp
#include <iostream>
#include <ostream>
#include <vector>
using namespace std;

int main() {
    vector<int> v;


    auto first = v.begin() + 1;
    auto last = v.begin() + 3;

    auto index = first - v.begin();
    v.erase(first, last);
    auto i = v.begin() + index;

    if (i == v.end()) {
        cout << "EPIC FAIL" << endl;
    } else {
        cout << "This should be 44: " << *i << endl;

C:\Temp>cl /EHsc /nologo /W4 /MTd purr.cpp

This should be 44: 44

Posted by BartoszMilewski on 4/1/2010 at 9:29 PM
Any chance for a workaround?
Posted by Stephan [MSFT] on 4/1/2010 at 8:21 PM

Thanks for reporting this bug. We're keeping it active, and we'll fix it in VC11.

If you have any questions, feel free to E-mail me at .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 3/28/2010 at 10:43 PM
Thanks for your feedback. We were able to reproduce the issue you are seeing. We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 3/27/2010 at 4:10 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(