Message ID | 20240808153054.1949621-1-ppalka@redhat.com |
---|---|
State | New |
Headers | show |
Series | c++: DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P cleanups | expand |
On 8/8/24 11:30 AM, Patrick Palka wrote: > 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 already was clearing it). > > Also the template depth comparison test within tsubst_friend_function is > equivalent to DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P since such templates > always have more levels than the class context, and it's not possible to > directly refer to an existing template that has more levels than the > current template context. OK. > 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 in the > new template code path after partial instantiation here ... > (tsubst_template_decl): ... instead of here. > --- > 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 677ed7d1289..d468a3037b6 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -11764,8 +11764,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); > @@ -11807,6 +11806,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)) > @@ -15008,8 +15008,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. */
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 677ed7d1289..d468a3037b6 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -11764,8 +11764,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); @@ -11807,6 +11806,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)) @@ -15008,8 +15008,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. */