[PATCH 1/2] c++: Print function template parms when relevant
Matthias Kretz
m.kretz@gsi.de
Fri Nov 26 15:24:44 GMT 2021
The choice when to print a function template parameter was still
suboptimal. That's because sometimes the function template parameter
list only adds noise, while in other situations the lack of a function
template parameter list makes diagnostic messages hard to understand.
The general idea of this change is to print template parms wherever they
would appear in the source code as well. Thus, the diagnostics code
needs to know whether any template parameter was given explicitly.
DWARF names of functions use dump_function_name to produce a name
without function arguments (function arguments are printed from
dump_function_decl). However, FLAGS should still state the intent of
printing a name without function arguments (TFF_NO_FUNCTION_ARGUMENTS so
that dump_function_name can decide correctly whether to call
dump_template_parms.
Based on an initial patch from Jason Merrill <jason@redhat.com>.
Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
gcc/testsuite/ChangeLog:
* g++.dg/debug/dwarf2/template-params-12n.C: Optionally, allow
DW_AT_default_value.
* g++.dg/diagnostic/default-template-args-1.C: New test.
* g++.dg/diagnostic/default-template-args-2.C: New test.
* g++.dg/diagnostic/default-template-args-3.C: New test.
* g++.dg/diagnostic/default-template-args-4.C: New test.
* g++.dg/diagnostic/default-template-args-5.C: New test.
* g++.dg/diagnostic/param-type-mismatch-2.C: Expect template
parms in diagnostic.
* g++.dg/ext/pretty1.C: Expect function template specialization
to not pretty-print template parms.
* g++.old-deja/g++.ext/pretty3.C: Ditto.
* g++.old-deja/g++.pt/memtemp77.C: Ditto.
* g++.dg/goacc/template.C: Expect function template parms for
explicit arguments.
* g++.dg/gomp/declare-variant-7.C: Expect no function template
parms for deduced arguments.
* g++.dg/template/error40.C: Expect only non-default template
arguments in diagnostic.
gcc/cp/ChangeLog:
* constraint.cc (get_mapped_args): Remove incorrect non-default
args count on multi-level template args; instead set the
non-default args count on each inner TREE_VEC.
* cp-tree.h: Rewrite NON_DEFAULT_TEMPLATE_ARGS_COUNT
implementation to store the number explicitly specified
arguments in a TREE_LIST.
(EXPLICIT_TEMPLATE_ARGS_P): New.
(SET_EXPLICIT_TEMPLATE_ARGS_P): New.
(set_non_default_template_args_count): New declaration.
(get_non_default_template_args_count): New declaration.
(set_explicit_template_args_count): New declaration.
(get_explicit_template_args_count): New declaration.
(TFF_AS_PRIMARY): New constant.
* decl.c (grokfndecl): Mark all template arguments in a friend
declaration as explicitly specified.
* error.c (args_or_non_default_template_args_count): Renamed
from get_non_default_template_args_count (name-clash). Make
independent of flag_pretty_templates.
(dump_template_bindings): Add flags parameter to be passed to
get_non_default_template_args_count. Print only non-default
template arguments. Add used_parms parameter: print defaulted
template bindings if the parameter name is part of used_parms.
(dump_substitution): Walk the function_decl to find all used
template parameters.
(dump_function_decl): Call dump_function_name and dump_type of
the DECL_CONTEXT with specialized template and set
TFF_AS_PRIMARY for their flags. Don't print template arguments.
dump_function_name already does so.
(dump_function_name): Add and document conditions for calling
dump_template_parms. Move DECL_USE_TEMPLATE to PRIMARY parameter
of dump_template_parms.
(dump_template_parms): Print only non-default template
parameters.
(lang_decl_name): Add TFF_NO_FUNCTION_ARGUMENTS to
dump_function_name flags.
* pt.c (set_non_default_template_args_count): New function.
(get_non_default_template_args_count): New function.
(set_explicit_template_args_count): New function.
(get_explicit_template_args_count): New function.
(expand_template_argument_pack): Always adjust and set
the adjusted non-default args count.
(template_parm_to_arg): SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT
independent of CHECKING_P.
(coerce_template_parameter_pack): Ditto.
(coerce_template_parms): Ditto.
(fn_type_unification): Ditto.
(type_unification_real): Ditto.
(get_partial_spec_bindings): Ditto.
(determine_specialization): Also copy the inner TREE_VECs.
(template_parms_level_to_args): Always count non-default args.
(copy_template_args): Only copy the non-default template args
count on TREE_VECs that should have it.
(fn_type_unification): Set EXPLICIT_TEMPLATE_ARGS_P on the
template arguments tree if any template parameter was explicitly
given.
(type_unification_real): Count non-default args sooner.
(get_partial_spec_bindings): Set non-default args count.
(tsubst_template_args): Take a shortcut for multi-level args to
avoid a lot of unnecessary checks and simplify non-default args
counting. Fix the count of non-default template arguments.
gcc/cp/constraint.cc | 3 +-
gcc/cp/cp-tree.h | 36 ++-
gcc/cp/decl.c | 4 +
gcc/cp/error.c | 200 +++++++++------
gcc/cp/pt.c | 232 ++++++++++++++----
.../g++.dg/debug/dwarf2/template-params-12n.C | 2 +-
.../diagnostic/default-template-args-1.C | 61 +++++
.../diagnostic/default-template-args-2.C | 37 +++
.../diagnostic/default-template-args-3.C | 29 +++
.../diagnostic/default-template-args-4.C | 19 ++
.../diagnostic/default-template-args-5.C | 12 +
.../g++.dg/diagnostic/param-type-mismatch-2.C | 2 +-
gcc/testsuite/g++.dg/ext/pretty1.C | 2 +-
gcc/testsuite/g++.dg/goacc/template.C | 8 +-
gcc/testsuite/g++.dg/gomp/declare-variant-7.C | 4 +-
gcc/testsuite/g++.dg/template/error40.C | 6 +-
gcc/testsuite/g++.old-deja/g++.ext/pretty3.C | 2 +-
gcc/testsuite/g++.old-deja/g++.pt/memtemp77.C | 2 +-
18 files changed, 508 insertions(+), 153 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/diagnostic/default-template-args-1.C
create mode 100644 gcc/testsuite/g++.dg/diagnostic/default-template-args-2.C
create mode 100644 gcc/testsuite/g++.dg/diagnostic/default-template-args-3.C
create mode 100644 gcc/testsuite/g++.dg/diagnostic/default-template-args-4.C
create mode 100644 gcc/testsuite/g++.dg/diagnostic/default-template-args-5.C
Dr. Matthias Kretz https://mattkretz.github.io
GSI Helmholtz Centre for Heavy Ion Research https://gsi.de
stdₓ::simd
──────────────────────────────────────────────────────────────────────────
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-c-Print-function-template-parms-when-relevant.patch
Type: text/x-patch
Size: 47690 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20211126/2647ee4d/attachment-0001.bin>
More information about the Gcc-patches
mailing list