From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 802D13858401; Tue, 24 Aug 2021 18:46:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 802D13858401 From: "fstqwq at foxmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/102048] New: __gnu_cxx::rope.erase(size_t __p) implementation seems to be wrong Date: Tue, 24 Aug 2021 18:46:56 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fstqwq at foxmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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 target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2021 18:46:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102048 Bug ID: 102048 Summary: __gnu_cxx::rope.erase(size_t __p) implementation seems to be wrong Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: fstqwq at foxmail dot com Target Milestone: --- In ext/rope from all versions of gcc I could refer to (see https://github.com/gcc-mirror/gcc/blame/master/libstdc%2B%2B-v3/include/ext= /rope#L2407, the last change is made 17 years ago), the implementation of __gnu_cxx::rope.erase(size_t) is: // Erase, single character void erase(size_type __p) { erase(__p, __p + 1); } The comment said it will erase a single character from rope. However, the function actually erase (__p + 1) characters starting from position __p by calling erase(size_t, size_t) commented as "Erase, (position, size) variant= .", which is just defined above the erase(size_t) version. You can test the function by the following code: #include #include int main() { __gnu_cxx::rope R; for (int i =3D 0; i < 9; i++) R.push_back(i); R.erase(2); for (int i =3D 0; i < 4; i++) std::cout << R[i] << std::endl;=20 } If erase functions normally or replace erase(2) with erase(2, 1), it's expe= cted to see 0 1 3 4. It turned out to be 0 1 5 6, that erases 3 elements starting from 2.=