From 9845b7b45621e3833aee47276cb111e43be0e48b Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Tue, 7 Jul 2020 16:33:12 -0400 Subject: c++: wrong pretty printing of nested type [PR95303] In the testcase below, we pretty print the nested type A::B as A::B because we don't check whether B is itself a class template before printing the innermost set of template arguments from B's TEMPLATE_INFO (which in this case belong to A). This patch fixes this by checking PRIMARY_TEMPLATE_P beforehand. gcc/cp/ChangeLog: PR c++/95303 * cxx-pretty-print.c (pp_cxx_unqualified_id): Check PRIMARY_TEMPLATE_P before printing the innermost template arguments. gcc/testsuite/ChangeLog: PR c++/95303 * g++.dg/concepts/diagnostic14.C: New test. --- gcc/cp/cxx-pretty-print.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'gcc/cp/cxx-pretty-print.c') diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 188462a..263f225 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -173,12 +173,13 @@ pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t) case UNBOUND_CLASS_TEMPLATE: pp_cxx_unqualified_id (pp, TYPE_NAME (t)); if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (t)) - { - pp_cxx_begin_template_argument_list (pp); - tree args = INNERMOST_TEMPLATE_ARGS (TI_ARGS (ti)); - pp_cxx_template_argument_list (pp, args); - pp_cxx_end_template_argument_list (pp); - } + if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti))) + { + pp_cxx_begin_template_argument_list (pp); + tree args = INNERMOST_TEMPLATE_ARGS (TI_ARGS (ti)); + pp_cxx_template_argument_list (pp, args); + pp_cxx_end_template_argument_list (pp); + } break; case BIT_NOT_EXPR: -- cgit v1.1