From 2cc7f90b6e4906efd9cd909d7182630dbf9e819b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 27 Jan 2015 16:40:45 -0500 Subject: [PATCH] re PR c++/58597 (ICE with lambda in default argument of template function) PR c++/58597 * lambda.c (maybe_add_lambda_conv_op): Check cfun rather than current_function_decl. From-SVN: r220192 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/lambda.c | 2 +- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg6.C | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg6.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b914f4b1334..2ae15d027d8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-01-27 Jason Merrill + PR c++/58597 + * lambda.c (maybe_add_lambda_conv_op): Check cfun rather than + current_function_decl. + PR c++/63889 * pt.c (finish_template_variable): Move from semantics.c. Handle multiple template arg levels. Handle coercion here. diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 6c9e224c0f4..b160c8cb7ae 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 00000000000..fe8767ac605 --- /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 struct A +{ + template A(T, int = []{ return 0; }()) {} +}; + +A a = 0;