Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 86899 invoked from network); 8 Jan 2008 21:29:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Jan 2008 21:29:14 -0000 Received: (qmail 88017 invoked by uid 500); 8 Jan 2008 21:28:55 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 88004 invoked by uid 500); 8 Jan 2008 21:28:55 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 87932 invoked by uid 99); 8 Jan 2008 21:28:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jan 2008 13:28:55 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jan 2008 21:28:28 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 2793D714231 for ; Tue, 8 Jan 2008 13:28:34 -0800 (PST) Message-ID: <26208386.1199827714160.JavaMail.jira@brutus> Date: Tue, 8 Jan 2008 13:28:34 -0800 (PST) From: "Martin Sebor (JIRA)" To: stdcxx-dev@incubator.apache.org Subject: [jira] Updated: (STDCXX-690) [LWG #198] std::reverse_iterator::operator*() invalidates cached values In-Reply-To: <3690830.1199827474118.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/STDCXX-690?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Martin Sebor updated STDCXX-690: -------------------------------- Priority: Minor (was: Major) > [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 > Reporter: Martin Sebor > Priority: Minor > > 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 > #include > struct Iterator: std::iterator > { > 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 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.