Issue Details (XML | Word | Printable)

Key: STDCXX-769
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Minor Minor
Assignee: Unassigned
Reporter: Farid Zaripov
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

__rw_debug_iter iterators are partially invalidated after swap() operation

Created: 16/Mar/08 05:37 AM   Updated: 16/Mar/08 11:29 PM
Return to search
Component/s: 24. Iterators
Affects Version/s: 4.1.2, 4.1.3, 4.1.4, 4.2.0
Fix Version/s: None

Time Tracking:
Not Specified

Environment: All
Issue Links:
Reference
 

Severity: Runtime Error
Resolution Date: 16/Mar/08 05:42 AM


 Description  « Hide
The __rw_debug_iter class contains pointer to associated container. After swap() operation the __rw_debug_iter iterators, obtained from container method (i.e. begin()) are associated with another container variable. Due to this any operation between iterators, obtained before swap and after swap will fail on assert (except operator==(), maybe some others).

The testcase:

test.cpp
#include <vector>
#include <cassert>

int main ()
{
    typedef std::vector<int> Vector;
    typedef Vector::iterator Iter;

    Vector v1, v2;
    v1.push_back (1);

    Iter v1_begin = v1.begin ();

    v1.swap (v2);

    assert (v1_begin == v2.begin ());
    assert (0 == v1_begin - v2.begin ());

    return 0;
};

The testcase result:

rw/_iterbase.h:527: int __thiscall __rw::__rw_debug_iter<class std::vector<int,class std::allocator<int> >,int *,int *>::operator -<int*>(const class __rw::__rw_debug_iter<class std::vector<int,class std::allocator<int> >,int *,int *> &) const: Assertion '_C_cont && _C_cont == __rhs._C_cont' failed.

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Farid Zaripov added a comment - 16/Mar/08 05:42 AM
This is a just documenting issue. I don't think that it's will be fixed, because it's can be fixed only by removing these asserts.

Closing as Won't Fix.


Martin Sebor added a comment - 16/Mar/08 08:43 PM
This is similar to STDCXX-635.

Martin Sebor added a comment - 16/Mar/08 08:44 PM
But we fixed STDCXX-635 which deals with invalidating deque::iterator after calling std::swap . How is this different?

Farid Zaripov added a comment - 16/Mar/08 09:03 PM
This issue talking about __rw_debug_iter wraper class, that used in debug builds in all container classes when _RWSTD_NO_DEBUG_ITER macro is not defined.

STDCXX-635 is related to deque iterator with no matter _RWSTD_NO_DEBUG_ITER defined or not.


Martin Sebor added a comment - 16/Mar/08 09:49 PM
I realize that, but I still don't understand why the debugging iterators shouldn't provide the same guarantees as the ordinary ones. If anything, they should be more robust, i.e., provide additional guarantees beyond those required of the ordinary ones.

Farid Zaripov added a comment - 16/Mar/08 11:09 PM
Then we should eliminate the debugging iterators at all, because all checks in it's members are using pointer to associated container and this pointer becomes invalid after swap operation.

Martin Sebor added a comment - 16/Mar/08 11:29 PM
Well, that sounds like a design problem with the debugging iterators. It may not be one that can be fixed without breaking binary compatibility but I think if it is, in fact, a problem (there's some question regarding what iterator validity means for non-invalidating operations like swap() or list::splice()), we must fix it.