From ab3daffcbf35566d468c3028e48068a481048baf Mon Sep 17 00:00:00 2001 From: Nathaniel Shead Date: Thu, 23 Nov 2023 23:15:19 +1100 Subject: [PATCH] c++: Clear uninstantiated template friend when instantiating [PR104234] Otherwise attempting to get the originating module declaration ICEs because the DECL_CHAIN of an instantiated friend template is no longer its context. PR c++/104234 PR c++/112580 gcc/cp/ChangeLog: * pt.cc (tsubst_template_decl): Clear DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P. gcc/testsuite/ChangeLog: * g++.dg/modules/pr104234.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/pt.cc | 2 ++ gcc/testsuite/g++.dg/modules/pr104234.C | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/pr104234.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 669d2ad65c3a..e9dcdb32c6cf 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -14790,6 +14790,8 @@ 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/testsuite/g++.dg/modules/pr104234.C b/gcc/testsuite/g++.dg/modules/pr104234.C new file mode 100644 index 000000000000..d81f0d435bcf --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr104234.C @@ -0,0 +1,16 @@ +// PR c++/104234 +// { dg-additional-options "-fmodules-ts" } + +template struct _Node_handle_common { + template friend class _Rb_tree; +}; +struct _Hashtable { + using node_type = _Node_handle_common; + node_type __trans_tmp_1; +}; +template class _Rb_tree { + struct _Rb_tree_impl { + _Rb_tree_impl(); + } _M_impl; +}; +_Rb_tree _M_tmap_; -- 2.47.2