aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-07-19 16:10:20 -0400
committerPatrick Palka <ppalka@redhat.com>2023-07-19 16:10:20 -0400
commit92d1425ca7804000cfe8aa635cf363a87d362d75 (patch)
treef294fbdb70576dac9c2f1a9c98e205d9dde290d4 /libcpp
parent01f6e8b013237041adeac370f8d229aea6304591 (diff)
downloadgcc-92d1425ca7804000cfe8aa635cf363a87d362d75.zip
gcc-92d1425ca7804000cfe8aa635cf363a87d362d75.tar.gz
gcc-92d1425ca7804000cfe8aa635cf363a87d362d75.tar.bz2
c++: redundant targ coercion for var/alias tmpls
When stepping through the variable/alias template specialization code paths, I noticed we perform template argument coercion twice: first from lookup_template_variable / instantiate_alias_template and again from tsubst_decl (during instantiate_template). It'd be nice to avoid this redundant second coercion. It turns out this coercion in tsubst_decl could be safely elided whenever fully specializing a primary variable/alias template, because we can rely on lookup_template_variable / instantiate_alias_template to already have coerced the arguments. The only other situation to consider seems to be when fully specializing a partial variable template specialization (from instantiate_template), in which case the passed 'args' are the (already coerced) arguments relative to the partial template, and the resulting 'argvec' are the (uncoerced) arguments relative to the primary template, so coercion is still necessary. But computing 'argvec' here is only really necessary in order to look up (and insert into) the specializations table. And instantiate_template already performs a lookup, so if we just made it register the resulting specialization too then we could avoid having to compute 'argvec' when called from instantiate_template, which in turns means we could avoid the coercion altogether. This patch implements this approach. gcc/cp/ChangeLog: * pt.cc (tsubst_function_decl): Add defaulted 'use_spec_table' flag parameter. Don't look up or insert into the specializations table if 'use_spec_table' is false. (tsubst_decl): Add defaulted 'use_spec_table' flag parameter. Check for error_mark_node. <case FUNCTION_DECL>: Pass 'use_spec_table' to tsubst_function_decl. <case TYPE/VAR_DECL>: Don't call coerce_template_parms. Don't look up or insert into the specializations table if 'use_spec_table' is false. Exit earlier if the substituted type is erroneous and we're not complaining, and do so for alias specializations as well. (instantiate_template): Pass false as 'use_spec_table' to tsubst_decl. Call register_specialization afterwards.
Diffstat (limited to 'libcpp')
0 files changed, 0 insertions, 0 deletions