public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "fstqwq at foxmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-102048-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102048 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 <bits/stdc++.h> #include <ext/rope> int main() { __gnu_cxx::rope<int> R; for (int i = 0; i < 9; i++) R.push_back(i); R.erase(2); for (int i = 0; i < 4; i++) std::cout << R[i] << std::endl; } If erase functions normally or replace erase(2) with erase(2, 1), it's expected to see 0 1 3 4. It turned out to be 0 1 5 6, that erases 3 elements starting from 2.
next reply other threads:[~2021-08-24 18:46 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-24 18:46 fstqwq at foxmail dot com [this message] 2021-08-24 19:07 ` [Bug libstdc++/102048] " redi at gcc dot gnu.org 2021-08-24 19:12 ` redi at gcc dot gnu.org 2021-08-24 19:34 ` fstqwq at foxmail dot com 2021-08-24 21:11 ` redi at gcc dot gnu.org 2021-08-25 15:20 ` fstqwq at foxmail dot com 2021-08-25 15:50 ` redi at gcc dot gnu.org 2021-08-25 21:29 ` cvs-commit at gcc dot gnu.org 2021-08-25 22:12 ` redi at gcc dot gnu.org 2021-10-12 19:41 ` cvs-commit at gcc dot gnu.org 2022-04-26 13:13 ` cvs-commit at gcc dot gnu.org 2022-05-06 8:30 ` jakub at gcc dot gnu.org 2022-05-06 12:35 ` redi at gcc dot gnu.org 2022-05-09 16:39 ` cvs-commit 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-102048-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).