c++: Improve printing of pointers-to-members [PR97406, PR85901]
authorMarek Polacek <polacek@redhat.com>
Wed, 14 Oct 2020 16:59:58 +0000 (12:59 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 15 Oct 2020 15:17:22 +0000 (11:17 -0400)
commit08e712211efa4f969a64c69bdacf6ab45104a094
tree6d0c834ab11719a8d7b94c5f9c866ebcb321063b
parentf2ff7d26722297558601fd943f8165a59833e8f9
c++: Improve printing of pointers-to-members [PR97406, PR85901]

This PR points out that when printing the parameter mapping for a
pointer-to-member-function, the output was truncated:

  [with T = void (X::*]

Fixed by printing the abstract declarator for pointers-to-members in
cxx_pretty_printer::type_id.  So now we print:

  [with T = void (X::*)()]

But when I tried a pointer-to-data-member, I got

  [with T = ‘offset_type’ not supported by simple_type_specifier)‘offset_type’ not supported by direct_abstract_declarator]

so had to fix that too so that we now print:

  [with T = int X::*]

or

  [with T = int (X::*)[5]]

when the type is an array type.  Which is what PR85901 was about.

gcc/cp/ChangeLog:

PR c++/97406
PR c++/85901
* cxx-pretty-print.c (pp_cxx_type_specifier_seq): Handle OFFSET_TYPE.
(cxx_pretty_printer::abstract_declarator): Fix the printing of ')'.
(cxx_pretty_printer::direct_abstract_declarator): Handle OFFSET_TYPE.
(cxx_pretty_printer::type_id): Likewise.  Print the abstract declarator
for pointers-to-members.

gcc/testsuite/ChangeLog:

PR c++/97406
PR c++/85901
* g++.dg/diagnostic/ptrtomem1.C: New test.
* g++.dg/diagnostic/ptrtomem2.C: New test.
gcc/cp/cxx-pretty-print.c
gcc/testsuite/g++.dg/diagnostic/ptrtomem1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/ptrtomem2.C [new file with mode: 0644]