]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/pretty-print.c
C/C++: fix quoting of "aka" typedef information (PR 62170)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 22 Nov 2017 20:37:58 +0000 (20:37 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Wed, 22 Nov 2017 20:37:58 +0000 (20:37 +0000)
commitce95abc41e998c8d1e1b2112a634d5a6cdd9ede0
tree1dfdcc2ae24d09d53824e4b7b34934a19d570519
parentd8d9aa38aed6489fa28308d3955e3467c5eb935b
C/C++: fix quoting of "aka" typedef information (PR 62170)

PR 62170 describes a problem with how the quoting in pp_format
interacts with the "aka" information for typedefs in %qT for
the C family of frontends, and also now for %qH and %qI in the
C++ frontend: we print:

  'Py_ssize_t* {aka int*}'
   ^^^^^^^^^^^^^^^^^^^^^^ colorized as "quote"

i.e.
  '[START_COLOR]Py_ssize_t* {aka int*}[END_COLOR]'

when we should print:

  'Py_ssize_t*' {aka 'int*'}
   ^^^^^^^^^^^        ^^^^ colorized as "quote"

i.e.
  '[START_COLOR]Py_ssize_t*[END_COLOR]' {aka '[START_COLOR]int*[END_COLOR]'}

where the opening and closing quote characters and colorization are
added by the 'q' handling within pp_format.

This patch fixes the quoting by updating the %T handling in C and C++
and the %H/%I handling in C++ to insert the quoting appropriately.
It converts the "quote" param of the pp_format_decoder callback from
bool to bool *, allowing for the %T and %H/%I handlers to write
false back to it, to avoid printing the closing quote for the cases
like the above where the trailing closing quote isn't needed.

It introduces pp_begin_quote/pp_end_quote to simplify this.  These
take a "bool show_color", rather than using "pp_show_color (pp)"
since cxx_pp's pp_show_color isn't currently initialized (since
cxx_initialize_diagnostics happens before diagnostic_color_init).

gcc/c/ChangeLog:
PR c++/62170
* c-objc-common.c (c_tree_printer): Convert penultimate param from
bool to bool *.  Within '%T' handling, if showing an "aka", use
"quoted" param to add appropriate quoting.

gcc/cp/ChangeLog:
PR c++/62170
* error.c (type_to_string): Add leading comment.  Add params
"postprocessed", "quote", and "show_color", using them to fix
quoting of the "aka" for types involving typedefs.
(arg_to_string): Update for new params to type_to_string.
(cxx_format_postprocessor::handle): Likewise.
(cp_printer): Convert penultimate param from bool to bool *.
Update call to type_to_string and calls to
defer_phase_2_of_type_diff.

gcc/fortran/ChangeLog:
PR c++/62170
* error.c (gfc_notify_std): Convert "quoted" param from bool to
bool *.

gcc/ChangeLog:
PR c++/62170
* pretty-print.c (pp_format): Move quoting implementation to
pp_begin_quote and pp_end_quote.  Update pp_format_decoder call
to pass address of "quote" local.
(pp_begin_quote): New function.
(pp_end_quote): New function.
* pretty-print.h (printer_fn): Convert penultimate param from bool
to bool *.
(pp_begin_quote): New decl.
(pp_end_quote): New decl.
* tree-diagnostic.c (default_tree_printer): Convert penultimate
param from bool to bool *.
* tree-diagnostic.h (default_tree_printer): Likewise.

gcc/testsuite/ChangeLog:
PR c++/62170
* g++.dg/diagnostic/aka1.C: Update expected error messages to
reflect fixes to quoting.
* g++.dg/diagnostic/aka2.C: New test case.
* g++.dg/parse/error55.C: Update expected error messages to
reflect fixes to quoting.
* gcc.dg/diag-aka-1.c: Likewise.
* gcc.dg/diag-aka-2.c: New test case.
* gcc.dg/pr13804-1.c: Update expected error messages to reflect
fixes to quoting.
* gcc.dg/pr56980.c: Likewise.
* gcc.dg/pr65050.c: Likewise.
* gcc.dg/redecl-14.c: Likewise.
* gcc.dg/utf16-4.c Likewise.
* gcc.target/i386/sse-vect-types.c (__m128d): Likewise.
* obj-c++.dg/invalid-type-1.mm: Likewise.
* objc.dg/proto-lossage-4.m: Likewise.

From-SVN: r255076
25 files changed:
gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-objc-common.c
gcc/cp/ChangeLog
gcc/cp/error.c
gcc/fortran/ChangeLog
gcc/fortran/error.c
gcc/pretty-print.c
gcc/pretty-print.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/aka1.C
gcc/testsuite/g++.dg/diagnostic/aka2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/error55.C
gcc/testsuite/gcc.dg/diag-aka-1.c
gcc/testsuite/gcc.dg/diag-aka-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr13804-1.c
gcc/testsuite/gcc.dg/pr56980.c
gcc/testsuite/gcc.dg/pr65050.c
gcc/testsuite/gcc.dg/redecl-14.c
gcc/testsuite/gcc.dg/utf16-4.c
gcc/testsuite/gcc.target/i386/sse-vect-types.c
gcc/testsuite/obj-c++.dg/invalid-type-1.mm
gcc/testsuite/objc.dg/proto-lossage-4.m
gcc/tree-diagnostic.c
gcc/tree-diagnostic.h