public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/102048] New: __gnu_cxx::rope.erase(size_t __p) implementation seems to be wrong
@ 2021-08-24 18:46 fstqwq at foxmail dot com
  2021-08-24 19:07 ` [Bug libstdc++/102048] " redi at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: fstqwq at foxmail dot com @ 2021-08-24 18:46 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2022-05-09 16:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24 18:46 [Bug libstdc++/102048] New: __gnu_cxx::rope.erase(size_t __p) implementation seems to be wrong fstqwq at foxmail dot com
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

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