From 2ddf4350d319a1eb95075513b27dee09523e9a90 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 19 Jun 2015 14:37:41 -0400 Subject: [PATCH] re PR c++/66585 (Internal compiler error when initialize field with lambda) PR c++/66585 * pt.c (instantiate_class_template_1): Clear cp_unevaluated_operand and c_inhibit_evaluation_warnings. From-SVN: r224684 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 16 ++++++++++++++++ .../g++.dg/cpp0x/lambda/lambda-nsdmi8.C | 15 +++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi8.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7d42381a474..080d3e11e79 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-06-18 Jason Merrill + + PR c++/66585 + * pt.c (instantiate_class_template_1): Clear + cp_unevaluated_operand and c_inhibit_evaluation_warnings. + 2015-06-19 Jason Merrill PR c++/65880 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 5dd5bfe55de..efb90e46f0f 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9215,12 +9215,20 @@ instantiate_class_template_1 (tree type) it now. */ push_deferring_access_checks (dk_no_deferred); + int saved_unevaluated_operand = cp_unevaluated_operand; + int saved_inhibit_evaluation_warnings = c_inhibit_evaluation_warnings; + fn_context = decl_function_context (TYPE_MAIN_DECL (type)); /* Also avoid push_to_top_level for a lambda in an NSDMI. */ if (!fn_context && LAMBDA_TYPE_P (type) && TYPE_CLASS_SCOPE_P (type)) fn_context = error_mark_node; if (!fn_context) push_to_top_level (); + else + { + cp_unevaluated_operand = 0; + c_inhibit_evaluation_warnings = 0; + } /* Use #pragma pack from the template context. */ saved_maximum_field_alignment = maximum_field_alignment; maximum_field_alignment = TYPE_PRECISION (pattern); @@ -9636,6 +9644,14 @@ instantiate_class_template_1 (tree type) } } + if (fn_context) + { + /* Restore these before substituting into the lambda capture + initializers. */ + cp_unevaluated_operand = saved_unevaluated_operand; + c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings; + } + if (tree expr = CLASSTYPE_LAMBDA_EXPR (type)) { tree decl = lambda_function (type); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi8.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi8.C new file mode 100644 index 00000000000..8c0adfad45f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi8.C @@ -0,0 +1,15 @@ +// PR c++/66585 +// { dg-do compile { target c++11 } } + +class A { + template using _Requires = int; + +public: + template > + A(_Functor); +}; +template class B { + A f = [](T) {}; +}; + +B a; -- 2.30.2