diff mbox

C++ PATCH to instantiation of lambda closure

Message ID 5643E2D8.4020300@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 12, 2015, 12:52 a.m. UTC
While looking into something else I noticed a GC problem with lambdas: 
it is possible to collect after instantiating the closure type, which 
implies instantiating the operator(), while we're in the middle of an 
expression, leading to corruption.  We deal with this sort of thing in 
mark_used by preventing collection, so let's do the same here.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit a881d7bf5eb64ee5f110ae0ff206805da560f3df
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 11 15:48:01 2015 -0500

    	* pt.c (instantiate_class_template_1): Set function_depth around
    	instantiation of lambda op().

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index bfea8e2..076c1c7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10168,7 +10168,12 @@  instantiate_class_template_1 (tree type)
 	{
 	  if (!DECL_TEMPLATE_INFO (decl)
 	      || DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) != decl)
-	    instantiate_decl (decl, false, false);
+	    {
+	      /* Set function_depth to avoid garbage collection.  */
+	      ++function_depth;
+	      instantiate_decl (decl, false, false);
+	      --function_depth;
+	    }
 
 	  /* We need to instantiate the capture list from the template
 	     after we've instantiated the closure members, but before we