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

--- Comment #9 from Pedro Alves <palves at redhat dot com> ---
> Sounds like Paul's original patch may have introduced an undesired 
> conflation.  AFAICS, options.addressprint's exists to implement "set print 
> address on/off", which had for original motivation, from the manual:

> Let's also take a look at what happens if you bypass the printer, with /r:

> (gdb) set print address off 
> (gdb) p /r it
> $6 = {_M_current = }
> (gdb) p /r it._M_current
> $7 = (C *) 
> (gdb) p /r *it._M_current 
> $8 = {ref = }
> (gdb) p /r it._M_current.ref
> $9 = (int &) 1

BTW, from the above, we can tell that the original problem with the printer is
not restricted to references (as per the subject).  Note above we skipped
printing the addresses of pointers, as expected due to "set print address off".

So if we tweak the original test to make "ref" a pointer instead:

#include <vector>
class C {
public:
  int *ref;
  C(int *ref_):ref(ref_) {}
};
int main() {
  int *d(nullptr);
  std::vector<C> vec({d});
  for (auto it=vec.begin();it!=vec.end();++it) {
    it->ref; // line 11
    __attribute__((unused)) C *gdb_stub(&*it);
  }
}

we get the same odd result:

(gdb) p it
$1 = {ref = }

Reply via email to