public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/50119] New: copy_n advances InputIterator one more time than necessary
@ 2011-08-18 14:57 cubbi at cubbi dot org
  2011-08-18 15:11 ` [Bug libstdc++/50119] " paolo.carlini at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: cubbi at cubbi dot org @ 2011-08-18 14:57 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50119

             Bug #: 50119
           Summary: copy_n advances InputIterator one more time than
                    necessary
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: cubbi@cubbi.org


The naive implementation of std::copy_n() incorrectly increments InputIterator
one more time than needed, which fails with single-pass input iterators such as
istream_iterator

Test program:

#include <algorithm>
#include <vector>
#include <sstream>
#include <iterator>
#include <iostream>
int main()
{
    std::istringstream s("1 2 3 4 5");
    std::vector<int> v;
    copy_n(std::istream_iterator<int>(s), 2, back_inserter(v));
    copy_n(std::istream_iterator<int>(s), 2, back_inserter(v));

    copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
    std::cout << '\n';
}

Output with GCC 4.5.3 and 4.7.0-alpha20110716
1 2 4 5
expected output:
1 2 3 4

Similar bug was fixed in LLVM's libc++ in february 2011, the fix is
straightforward:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110221/039404.html


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-08-18 16:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-18 14:57 [Bug libstdc++/50119] New: copy_n advances InputIterator one more time than necessary cubbi at cubbi dot org
2011-08-18 15:11 ` [Bug libstdc++/50119] " paolo.carlini at oracle dot com
2011-08-18 16:36 ` [Bug libstdc++/50119] [C++0x] " paolo at gcc dot gnu.org
2011-08-18 16:41 ` paolo.carlini at oracle dot com

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).