This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PR c++/85634] Fix tsubst ICE


On 06/20/2018 10:33 AM, Nathan Sidwell wrote:
This patch fixes 85634, an ice during tsubst where we encounter an unmarked lookup.  Such lookups could be mutated by declarations added after the template definition containing them.   That would be bad.

This patch is needed on trunk, to handle friends of templates. I happened to leave the equivalent marking of a template-id-expr in the gcc-8 branch, so it's not needed there (but does mark more than necessary).

nathan
--
Nathan Sidwell
2018-06-20  Nathan Sidwell  <nathan@acm.org>

	PR c++/85634
	* friend.c (add_friend): Keep lookup sets of tempate sets.

	PR c++/85634
	* g++.dg/lookup/pr85634-2.C: New.

Index: gcc/cp/friend.c
===================================================================
--- gcc/cp/friend.c	(revision 261814)
+++ gcc/cp/friend.c	(working copy)
@@ -173,6 +173,12 @@ add_friend (tree type, tree decl, bool c
   if (decl == error_mark_node)
     return;
 
+  if (TREE_CODE (decl) == FUNCTION_DECL
+      && DECL_TEMPLATE_INSTANTIATION (decl))
+    /* We'll have parsed this as a declaration, and therefore not
+       marked the lookup set for keeping.  Do that now.  */
+    lookup_keep (DECL_TI_TEMPLATE (decl));
+
   typedecl = TYPE_MAIN_DECL (type);
   list = DECL_FRIENDLIST (typedecl);
   name = DECL_NAME (decl);
Index: gcc/testsuite/g++.dg/lookup/pr85634-2.C
===================================================================
--- gcc/testsuite/g++.dg/lookup/pr85634-2.C	(revision 0)
+++ gcc/testsuite/g++.dg/lookup/pr85634-2.C	(working copy)
@@ -0,0 +1,16 @@
+// PR c++/85634
+
+namespace bsl {
+  template <class T> void frob (const T *);
+}
+
+using namespace bsl;
+
+template<class VALUE> void frob (const VALUE &);
+
+template <typename T>
+struct TPL {
+  friend void frob <T> (const T &);
+};
+
+TPL<int> x;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]