]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P tweaks
authorPatrick Palka <ppalka@redhat.com>
Sat, 10 Aug 2024 01:13:05 +0000 (21:13 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sat, 10 Aug 2024 01:13:05 +0000 (21:13 -0400)
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 <jason@redhat.com>
gcc/cp/pt.cc

index 1dde7d167fd669cf52b8edf5872f288ad8d5755a..c1d4cdc7e2590b70a8673dd7428c77f497b8aa5a 100644 (file)
@@ -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.  */