]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: deferring partial substitution into lambda [PR116567]
authorPatrick Palka <ppalka@redhat.com>
Sat, 7 Sep 2024 18:06:37 +0000 (14:06 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sat, 7 Sep 2024 18:06:37 +0000 (14:06 -0400)
commitdfb63765e994bee74d533c810fdf75d3269530ad
treea960f31b31e6b9579047f4bccef2b40ca559ee63
parent506417dbc8b1cbc1133a5322572cf94b671aadf6
c++: deferring partial substitution into lambda [PR116567]

Here we correctly defer partial substitution into the lambda used as
a default template argument, but then incorrectly perform the full
substitution, because add_extra_args adds outer template arguments from
the full substitution that are not related to the original template
context of the lambda.  For example, the template depth of the first
lambda is 1 but add_extra_args return a set of args with 3 levels, with
the inner level corresponding to the parameters of v1 (good) and the
outer levels corresponding to those of A and B (bad).

For the cases that we're interested in, add_extra_args can assume that
the deferred args are a full set of template arguments, and so it
suffices to just substitute into the deferred args and not do any
additional merging.

This patch refines add_extra_args accordingly, and additionally
makes it look for the tf_partial flag instead of for dependent args to
decide if the deferred substitution is a partial one.  This reveals we
were neglecting to set tf_partial when substituting into a default
template argument in a template context.

PR c++/116567

gcc/cp/ChangeLog:

* pt.cc (coerce_template_parms): Set tf_partial when substituting
into a default template argument in a template context.
(build_extra_args): Set TREE_STATIC on the deferred args if this
is a partial substitution.
(add_extra_args): Check TREE_STATIC instead of dependence of args.
Adjust merging behavior in that case.
(tsubst_lammda_expr): Check for tf_partial instead of dependence
of args when determining whether to defer substitution.
(tsubst_expr) <case LAMBDA_EXPR>: Remove tf_partial early exit.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-targ7.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/lambda-targ7.C [new file with mode: 0644]