]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Clear uninstantiated template friend when instantiating [PR104234]
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 23 Nov 2023 12:15:19 +0000 (23:15 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Mon, 11 Dec 2023 02:33:52 +0000 (13:33 +1100)
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 <nathanieloshead@gmail.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/modules/pr104234.C [new file with mode: 0644]

index 669d2ad65c3a0f0059e4fb45fdd22d88e5aa0858..e9dcdb32c6cf443448c9820206768714597e3227 100644 (file)
@@ -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 (file)
index 0000000..d81f0d4
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/104234
+// { dg-additional-options "-fmodules-ts" }
+
+template <typename> struct _Node_handle_common {
+  template <typename> friend class _Rb_tree;
+};
+struct _Hashtable {
+  using node_type = _Node_handle_common<int>;
+  node_type __trans_tmp_1;
+};
+template <typename> class _Rb_tree {
+  struct _Rb_tree_impl {
+    _Rb_tree_impl();
+  } _M_impl;
+};
+_Rb_tree<int> _M_tmap_;