[
https://issues.apache.org/jira/browse/STDCXX-690?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Martin Sebor updated STDCXX-690:
--------------------------------
Affects Version/s: 4.2.1
Fix Version/s: 4.3
Remaining Estimate: 8h
Original Estimate: 8h
This is a problem with the standard. Since issue 198 has already been
incorporated into the spec we need to write up a new one to revert it or
otherwise plug this hole. Scheduled for 4.3 although I suspect that may not be
enough time to get consensus from the C++ committee. If not, we'll reschedule.
> [LWG #198] std::reverse_iterator::operator*() invalidates cached values
> -----------------------------------------------------------------------
>
> Key: STDCXX-690
> URL: https://issues.apache.org/jira/browse/STDCXX-690
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 24. Iterators
> Affects Versions: 4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
> Reporter: Martin Sebor
> Priority: Minor
> Fix For: 4.3
>
> Original Estimate: 8h
> Remaining Estimate: 8h
>
> According to LWG issue 198
> (http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198), the
> implementation of reverse_iterator::operator*() should cache the "base"
> iterator to prevent dangling references to values cached by it. The test case
> below demonstrates the problem caused by not doing so:
> $ cat t.cpp && make t && ./t
> #include <cassert>
> #include <iterator>
> struct Iterator: std::iterator<std::random_access_iterator_tag, int>
> {
> int *cur;
> int cache;
> Iterator (int *p = 0): cur (p) { }
> ~Iterator () { cache = ~cache; }
> reference operator*() { return cache; }
> Iterator& operator++() { cache = *++cur; return *this; }
> Iterator& operator--() { cache = *--cur; return *this; }
> };
> int main ()
> {
> int a[] = { 1, 2, 3 };
> Iterator it (a + sizeof a / sizeof *a);
> std::reverse_iterator<Iterator> rit (it);
> const int &ref = *rit;
> const int val = ref;
> ++rit;
> assert (val == ref);
> }
> gcc -c -I/home/sebor/stdcxx/include/ansi -D_RWSTDDEBUG -pthread
> -I/home/sebor/stdcxx/include -I/build/sebor/stdcxx-gcc-4.1.2-15D/include
> -I/home/sebor/stdcxx/examples/include -pedantic -nostdinc++ -g -W -Wall
> -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long -Wcast-align
> t.cpp
> gcc t.o -o t -pthread -L/build/sebor/stdcxx-gcc-4.1.2-15D/lib
> -Wl,-R/build/sebor/stdcxx-gcc-4.1.2-15D/lib -lstd15D -lsupc++ -lm
> t: t.cpp:29: int main(): Assertion `val == ref' failed.
> Aborted
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.