public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakobsybren at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-51823-4@http.gcc.gnu.org/bugzilla/> (raw) 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: <iterator> 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.
next reply other threads:[~2012-01-11 12:58 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-01-11 12:58 jakobsybren at gmail dot com [this message] 2012-01-11 13:16 ` [Bug libstdc++/51823] " redi at gcc dot gnu.org 2012-01-11 13:40 ` jakobsybren at gmail dot com 2012-01-11 13:56 ` redi at gcc dot gnu.org 2012-01-11 14:08 ` redi at gcc dot gnu.org 2012-01-11 14:19 ` redi at gcc dot gnu.org 2012-01-11 14:37 ` redi at gcc dot gnu.org 2012-01-11 15:17 ` marc.glisse at normalesup dot org 2012-01-11 15:26 ` [Bug libstdc++/51823] [DR 198] reverse iterator returns uninitialized values redi at gcc dot gnu.org 2012-01-11 15:48 ` marc.glisse at normalesup dot org 2012-01-11 15:59 ` redi at gcc dot gnu.org 2012-01-14 16:38 ` redi at gcc dot gnu.org 2012-08-22 19:19 ` redi at gcc dot gnu.org 2012-10-30 23:49 ` dave at boostpro dot com 2012-10-31 0:37 ` redi at gcc dot gnu.org 2012-12-13 12:24 ` [Bug libstdc++/51823] [DR 198] [DR 2204] " redi at gcc dot gnu.org 2012-12-14 16:35 ` dave at boostpro dot com 2014-02-19 21:02 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-51823-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).