Home Dashboard Directory Help
Search

Visual C++ iterator debugging incorrectly raises assertion on correct use of return value of std::vector::erase() by James McNellis


Status: 

Active


4
0
Sign in
to vote
Type: Bug
ID: 557029
Opened: 5/4/2010 9:15:21 PM
Access Restriction: Public
0
Workaround(s)
view
4
User(s) can reproduce this bug

Description

In Visual C++ 2010, given the following code:

#include <vector>

int main()
{
    std::vector<int> v(3);
    std::vector<int>::const_iterator it(v.erase(v.begin(), v.end()));
    bool b(it == v.end());
}

a debug build with _HAS_ITERATOR_DEBUGGING enabled will raise an assertion on the last line with the expression "vector iterators incompatible."

The return value of this overload of std::vector::erase() is an iterator pointing to the element after the erasure, or end() if the last element was erased.

In the example code, "it" is a valid iterator, and the comparison with "v.end()" should return true. It does, in fact, return true when "_HAS_ITERATOR_DEBUGGING = 0" is added to the top of the source file.
Details
Sign in to post a comment.
Posted by Microsoft on 6/22/2010 at 3:15 PM
Hi,

I'm not sure if you're notified when the primary bug is updated, so I wanted to let you know that we've fixed this and the fix will be available in VC11.

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by James McNellis on 6/10/2010 at 3:32 PM
Stephan,

Oops; sorry--I couldn't find that one when I posted this one.

Thanks.
Posted by Microsoft on 6/10/2010 at 12:37 PM
Hi,

Thanks for reporting this bug. I've resolved it as a duplicate of http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=545013 , where I explained a workaround.

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Phil Devaney2 on 5/6/2010 at 6:34 AM
I have also experience this bug. The problem is that erase returns an iterator that doesn't have _Myproxy set.

In VS 2008, vector::erase returns the following:

#if _HAS_ITERATOR_DEBUGGING
        return (iterator(_First._Myptr, this));
#else
    return (_First);
#endif

In VS 2010, it returns simply:

return (_First);
Posted by Microsoft on 5/5/2010 at 7:53 PM
Thank you for reporting this issue.
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 5/4/2010 at 9:34 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.