diff mbox

[C++] PR 51227

Message ID 4ECE3719.5050208@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Nov. 24, 2011, 12:22 p.m. UTC
Hi,

this is an ICE on invalid: toward the end of 
instantiate_class_template_1 we call lambda_function without checking 
its return value for NULL_TREE (it can well be so) and we pass it 
directly to instantiate_decl which doesn't know how to cope with that. 
But everything is wrong in that case, the next maybe_add_lambda_conv_op 
would also crash anyway. Thus the below, tested x86_64-linux.

Ok for mainline, or we want to do something more sophisticated, maybe 
earlier?

Thanks,
Paolo.

//////////////////////
/cp
2011-11-24  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51227
	* pt.c (instantiate_class_template_1): If lambda_function (type)
	is NULL_TREE do not instantiate_decl.

/testsuite
2011-11-24  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51227
	* g++.dg/cpp0x/lambda/lambda-ice5.C: New.

Comments

Jason Merrill Nov. 24, 2011, 4:43 p.m. UTC | #1
On 11/24/2011 07:22 AM, Paolo Carlini wrote:
> Ok for mainline, or we want to do something more sophisticated, maybe
> earlier?

OK, but in the case that decl is null, let's gcc_assert (errorcount); 
that should never happen for well-formed code.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/cpp0x/lambda/lambda-ice5.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-ice5.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-ice5.C	(revision 0)
@@ -0,0 +1,12 @@ 
+// PR c++/51227
+// { dg-options "-std=c++0x" }
+
+template<int> int foo()
+{
+  [] (void i) { return 0; } (0); // { dg-error "incomplete|invalid|no match" }
+}
+
+void bar()
+{
+  foo<0>();
+}
Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 181689)
+++ cp/pt.c	(working copy)
@@ -9103,14 +9103,18 @@  instantiate_class_template_1 (tree type)
 
   if (CLASSTYPE_LAMBDA_EXPR (type))
     {
-      tree lambda = CLASSTYPE_LAMBDA_EXPR (type);
-      if (LAMBDA_EXPR_DEDUCE_RETURN_TYPE_P (lambda))
+      tree decl = lambda_function (type);
+      if (decl)
 	{
-	  apply_lambda_return_type (lambda, void_type_node);
-	  LAMBDA_EXPR_RETURN_TYPE (lambda) = NULL_TREE;
+	  tree lambda = CLASSTYPE_LAMBDA_EXPR (type);
+	  if (LAMBDA_EXPR_DEDUCE_RETURN_TYPE_P (lambda))
+	    {
+	      apply_lambda_return_type (lambda, void_type_node);
+	      LAMBDA_EXPR_RETURN_TYPE (lambda) = NULL_TREE;
+	    }
+	  instantiate_decl (decl, false, false);
+	  maybe_add_lambda_conv_op (type);
 	}
-      instantiate_decl (lambda_function (type), false, false);
-      maybe_add_lambda_conv_op (type);
     }
 
   /* Set the file and line number information to whatever is given for