https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116567

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>:

https://gcc.gnu.org/g:dfb63765e994bee74d533c810fdf75d3269530ad

commit r15-3530-gdfb63765e994bee74d533c810fdf75d3269530ad
Author: Patrick Palka <ppa...@redhat.com>
Date:   Sat Sep 7 14:06:37 2024 -0400

    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 <ja...@redhat.com>

Reply via email to