https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124550

            Bug ID: 124550
           Summary: pretty printing list::reverse_iterator gives wrong
                    element
           Product: gcc
           Version: 15.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: subscribe at teskor dot de
  Target Milestone: ---

Created attachment 63957
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63957&action=edit
mentioned source file

When prettyprinting a list::reverse_iterator, the wrong list element is shown.
Example:
$ cat reverse_it.cpp
#include <iostream>
#include <list>
int main(void)
{
    std::list<int> foo {1,2,3,4,5,6,7};
    auto x = foo.rbegin();
    x++;
    std::cout << "*x is " << *x << "\n";
    return 0;
}
$ gdb reverse_it 
...
(gdb) b reverse_it.cpp:9
Breakpoint 1 at 0x4012c0: file reverse_it.cpp, line 9.
(gdb) run
Starting program: /home/michael.teske/src/reverse_it 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib64/libthread_db.so.1".
*x is 6

Breakpoint 1, main () at reverse_it.cpp:9
9           return 0;
(gdb) p x
$1 = {<std::iterator<std::bidirectional_iterator_tag, int, long, int*, int&>> =
{<No data fields>}, current = 7}
(gdb) p *x
$2 = (int &) @0x416f60: 6
(gdb) ptype x
type = class std::reverse_iterator<std::_List_iterator<int> > [with _Iterator =
std::_List_iterator<int>] : public
std::iterator<std::bidirectional_iterator_tag, int, long, int*, int&> 
...
As you see, printing x does treat it as a normal iterator, which is off by one. 
My suspicion is, that the python prettyprinter uses 
(gdb) p *((int*) &((('std::_List_node<int>' *) x.current._M_node)->_M_storage))
$3 = 7
instead of
(gdb) p *((int*) &((('std::_List_node<int>' *)
x.current._M_node->_M_prev)->_M_storage))
$4 = 6

Reply via email to