Here, sometimes we can end up in maybe_add_lambda_conv_op with
current_function_decl set but not cfun. If we push_function_context in
that case, the later pop doesn't clear cfun, but leaves it with a value
that leads to a crash later on. So let's avoid calling
push_function_context in that case.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit ce65568ba19c4613c25f48064a0d5e66454265ac
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Jan 27 14:26:18 2015 -0500
PR c++/58597
* lambda.c (maybe_add_lambda_conv_op): Check cfun rather than
current_function_decl.
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 6c9e224..b160c8c 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -854,7 +854,7 @@ prepare_op_call (tree fn, int nargs)
void
maybe_add_lambda_conv_op (tree type)
{
- bool nested = (current_function_decl != NULL_TREE);
+ bool nested = (cfun != NULL);
bool nested_def = decl_function_context (TYPE_MAIN_DECL (type));
tree callop = lambda_function (type);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg6.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg6.C
new file mode 100644
index 0000000..fe8767a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg6.C
@@ -0,0 +1,9 @@
+// PR c++/58597
+// { dg-do compile { target c++11 } }
+
+template<typename> struct A
+{
+ template<typename T> A(T, int = []{ return 0; }()) {}
+};
+
+A<int> a = 0;