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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>:

https://gcc.gnu.org/g:6b3302da9ef26aa11940f8c0dc92bec19e15c09b

commit r10-7007-g6b3302da9ef26aa11940f8c0dc92bec19e15c09b
Author: Marek Polacek <pola...@redhat.com>
Date:   Tue Mar 3 17:56:44 2020 -0500

    c++: Fix mismatch in template argument deduction [PR90505]

    My GCC 9 patch for C++20 P0846R0 (ADL and function templates) tweaked
    cp_parser_template_name to only return an identifier if name lookup
    didn't find anything.  In the deduce4.C case it means that we now
    return an OVERLOAD.  That means that cp_parser_template_id will call
    lookup_template_function whereby producing a TEMPLATE_ID_EXPR with
    unknown_type_node.  Previously, we created a TEMPLATE_ID_EXPR with
    no type, making it type-dependent.  What we have now is no longer
    type-dependent.  And so, when we call finish_call_expr after we've
    parsed "foo<int>(10)", even though we're in a template, we still do
    the normal processing, thus perform overload resolution.  When adding
    the template candidate foo we need to deduce the template arguments,
    and that is where things go downhill.

    When fn_type_unification sees that we have explicit template arguments,
    but they aren't complete, it will use them to substitute the function
    type.  So we substitute e.g. "void <T33d> (U)".  But the explicit
    template argument was for a different parameter so we don't actually
    substitute anything.  But the problem here was that we reduced the
    template level of 'U' anyway.  So then when we're actually deducing
    the template arguments via type_unification_real, we fail in unify:
    22932       if (TEMPLATE_TYPE_LEVEL (parm)
    22933           != template_decl_level (tparm))
    22934         /* The PARM is not one we're trying to unify.  Just check
    22935            to see if it matches ARG.  */
    because 'parm' has been reduced but 'tparm' has not yet.

    Therefore we shouldn't reduce the template level of template parameters
    when tf_partial aka template argument deduction substitution.  But we
    can only return after performing the cp_build_qualified_type etc.
    business otherwise things break horribly.

    2020-03-03  Jason Merrill  <ja...@redhat.com>
            Marek Polacek  <pola...@redhat.com>

        PR c++/90505 - mismatch in template argument deduction.
        * pt.c (tsubst): Don't reduce the template level of template
        parameters when tf_partial.

        * g++.dg/template/deduce4.C: New test.
        * g++.dg/template/deduce5.C: New test.
        * g++.dg/template/deduce6.C: New test.
        * g++.dg/template/deduce7.C: New test.

Reply via email to