From: Patrick Palka Date: Sat, 22 Mar 2025 14:18:07 +0000 (-0400) Subject: c++: ICE w/ dependently scoped template friend [PR119378] X-Git-Tag: releases/gcc-14.3.0~365 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d025b6880cde2cb2063b4d34546cdd70e5526e74;p=thirdparty%2Fgcc.git c++: ICE w/ dependently scoped template friend [PR119378] Here we ICE during instantiation of the dependently scoped template friend template struct friend class A::B; ultimately because processing_template_decl isn't set during substitution into the A scope. Since it's naturally a partial substitution, we need to make sure the flag is set. For GCC 15, this is already fixed similarly by r15-123. PR c++/119378 gcc/cp/ChangeLog: * pt.cc (tsubst) : Set processing_template_decl when substituting the context. gcc/testsuite/ChangeLog: * g++.dg/template/friend85.C: New test. Reviewed-by: Jason Merrill --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index ca34ed75d65..2efc7eb19e8 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -16946,8 +16946,10 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) case UNBOUND_CLASS_TEMPLATE: { + ++processing_template_decl; tree ctx = tsubst_aggr_type (TYPE_CONTEXT (t), args, complain, in_decl, /*entering_scope=*/1); + --processing_template_decl; tree name = TYPE_IDENTIFIER (t); tree parm_list = DECL_TEMPLATE_PARMS (TYPE_NAME (t)); diff --git a/gcc/testsuite/g++.dg/template/friend85.C b/gcc/testsuite/g++.dg/template/friend85.C new file mode 100644 index 00000000000..5cf83911193 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend85.C @@ -0,0 +1,16 @@ +// PR c++/119378 + +template +struct A { + template + struct B; +}; + +template +struct C { + template + template + friend class A::B; +}; + +template struct C;