https://gcc.gnu.org/g:70da0ca1239faefa6dec0494a85e998eae34beff

commit r15-2863-g70da0ca1239faefa6dec0494a85e998eae34beff
Author: Patrick Palka <ppa...@redhat.com>
Date:   Fri Aug 9 21:13:05 2024 -0400

    c++: DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P tweaks
    
    DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P templates can only appear as part
    of a template friend declaration, and in turn get partially instantiated
    only from tsubst_friend_function or tsubst_friend_class.  So rather than
    having tsubst_template_decl clear the flag, let's leave it up to the
    tsubst friend routines to clear it so that template friend handling stays
    localized (note that tsubst_friend_function was already clearing it).
    
    Also the template depth comparison test within tsubst_friend_function is
    equivalent to DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P since such templates
    belong to the class context (and so always have more levels than the
    context), and conversely and it isn't possible to directly refer to an
    existing template that has more levels than the class context.
    
    gcc/cp/ChangeLog:
    
            * pt.cc (tsubst_friend_class): Simplify depth comparison test
            in the redeclaration code path to
            DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P.  Clear the flag after
            partial instantiation here ...
            (tsubst_template_decl): ... instead of here.
    
    Reviewed-by: Jason Merrill <ja...@redhat.com>

Diff:
---
 gcc/cp/pt.cc | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 1dde7d167fd6..c1d4cdc7e259 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -11772,8 +11772,7 @@ tsubst_friend_class (tree friend_tmpl, tree args)
           compatible with the attachment of the friend template.  */
        module_may_redeclare (tmpl, friend_tmpl);
 
-      if (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (friend_tmpl))
-         > TMPL_ARGS_DEPTH (args))
+      if (DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (friend_tmpl))
        {
          tree parms = tsubst_template_parms (DECL_TEMPLATE_PARMS (friend_tmpl),
                                              args, tf_warning_or_error);
@@ -11815,6 +11814,7 @@ tsubst_friend_class (tree friend_tmpl, tree args)
          CLASSTYPE_USE_TEMPLATE (TREE_TYPE (tmpl)) = 0;
          CLASSTYPE_TI_ARGS (TREE_TYPE (tmpl))
            = INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (TREE_TYPE (tmpl)));
+         DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (tmpl) = false;
 
          /* Substitute into and set the constraints on the new declaration.  */
          if (tree ci = get_constraints (friend_tmpl))
@@ -15044,8 +15044,6 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t 
complain,
   if (PRIMARY_TEMPLATE_P (t))
     DECL_PRIMARY_TEMPLATE (r) = r;
 
-  DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (r) = false;
-
   if (!lambda_fntype && !class_p)
     {
       /* Record this non-type partial instantiation.  */

Reply via email to