From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26568 invoked by alias); 27 Jan 2015 03:49:02 -0000 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 Received: (qmail 26441 invoked by uid 48); 27 Jan 2015 03:48:47 -0000 From: "alex-j-a at hotmail dot co.uk" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/64814] New: std::copy_n advances InputIterator one *less* time than necessary. Date: Tue, 27 Jan 2015 03:49: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-Version: 4.9.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: alex-j-a at hotmail dot co.uk X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-01/txt/msg02991.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64814 Bug ID: 64814 Summary: std::copy_n advances InputIterator one *less* time than necessary. Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: major Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: alex-j-a at hotmail dot co.uk Bug 50119 is related. The issue should be clear from the example below; I've confirmed the output on several web-based compilers (I'm using a chromebook in standard config) all of which claim to use GCC. minimal failing example: #include #include #include #include #include int main() { std::istringstream ss("123456789012"); std::string output; auto readIter = std::istreambuf_iterator(ss); for (int i = 0; i < 3; ++i) { output.clear(); auto inserter = std::back_inserter(output); // Works - outputs 123456789012 //for (int j = 0; j < 4; ++j) // *inserter++ = *readIter++; // Doesn't work - outputs 123445677890 std::copy_n(readIter, 4, inserter); std::cout << output; } } The following works perfectly as a drop-in replacement from my tests: template OutputIt copy_n(InputIt first, SizeT count, OutputIt result) { for (; count > 0; --count) *result++ = *first++; return result; }