From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12992 invoked by alias); 11 Jan 2012 12:58:43 -0000 Received: (qmail 12981 invoked by uid 22791); 11 Jan 2012 12:58:42 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ,TW_CX,TW_DC,TW_GX X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Jan 2012 12:58:29 +0000 From: "jakobsybren at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/51823] New: reverse iterator instantiated with POD type returns uninitialized values + work around Date: Wed, 11 Jan 2012 12:58:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakobsybren at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg01192.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51823 Bug #: 51823 Summary: reverse iterator instantiated with POD type returns uninitialized values + work around Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: jakobsybren@gmail.com Created attachment 26299 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26299 *.i* output of minimal example that reproduces the bug System info: $ uname -a Linux ****** 3.0.0-14-generic #23-Ubuntu SMP Mon Nov 21 20:28:43 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux $ g++ -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) Attachment: * ostream_iterator_reverse_iterator.ii: output of: g++ -save-temps -o ostream_iterator_reverse_iterator -Wall ostream_iterator_reverse_iterator.cc where ostream_iterator_reverse_iterator.cc is a minimal example that reproduces the bug. Headerfiles involved: Compile command: g++ -o ostream_iterator_reverse_iterator -Wall ostream_iterator_reverse_iterator.cc Description: Consider an iterator class that implements the requirements of a forward_iterator. We underlying datatype is always POD and the operator*() member of the iterator returns the results by value, since it is POD anyway. Upon creating a reverse_iterator from this class a simple for-loop produces the expected results: Returning 9 9 Returning 8 8 Returning 7 7 Returning 6 6 Returning 5 5 Returning 4 4 Returning 3 3 Returning 2 2 Returning 1 1 Returning 0 0 but using the reverse_iterator in std::copy() with std::ostream_iterator produces: Returning 9 32767 Returning 8 32767 Returning 7 32767 Returning 6 32767 Returning 5 32767 Returning 4 32767 Returning 3 32767 Returning 2 32767 Returning 1 32767 Returning 0 32767 It seems that the internal value does not get copied. When using -O3 both the for-loop and the copy() construct produce 0 (zero) for each call to operator*() in the reverse_iterator, but not in the normal iterator. The 'work-around' forces the use of forwarding. I put it as comment in the minimum example. If I should have attached a separate source file with just the operator*()-line replaced, I wish to express my apologies in advance. The source file with the work-around instead of the original version of operator*() needs an additional compiler option though: -std=c++0x However, even with this version, the result with -O3 is still all zeros; not what I expected, but since that is the same as before, I guess that is more likely to be me misunderstanding what is supposed to happen with -O3 switched on.