From 6781e2af709464df449604e222514f2d613e7666 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 21 Jul 2016 23:45:54 -0400 Subject: [PATCH] PR c++/69223 - ICE with deduced template return type. * semantics.c (apply_deduced_return_type): Call complete_type_or_else before building the new RESULT_DECL. From-SVN: r238624 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/semantics.c | 6 ++++-- .../g++.dg/cpp0x/lambda/lambda-deduce3.C | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 603758cbd90..a3cc08198d3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2016-07-21 Jason Merrill + PR c++/69223 + * semantics.c (apply_deduced_return_type): Call + complete_type_or_else before building the new RESULT_DECL. + PR c++/71274 * decl2.c (maybe_instantiate_decl): Split out from mark_used. (decl_constant_var_p): Use it instead. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 19daeff4a44..63063b84bfc 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9279,6 +9279,10 @@ apply_deduced_return_type (tree fco, tree return_type) if (TREE_TYPE (result) == return_type) return; + if (!processing_template_decl && !VOID_TYPE_P (return_type) + && !complete_type_or_else (return_type, NULL_TREE)) + return; + /* We already have a DECL_RESULT from start_preparsed_function. Now we need to redo the work it and allocate_struct_function did to reflect the new type. */ @@ -9294,8 +9298,6 @@ apply_deduced_return_type (tree fco, tree return_type) if (!processing_template_decl) { - if (!VOID_TYPE_P (TREE_TYPE (result))) - complete_type_or_else (TREE_TYPE (result), NULL_TREE); bool aggr = aggregate_value_p (result, fco); #ifdef PCC_STATIC_STRUCT_RETURN cfun->returns_pcc_struct = aggr; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce3.C new file mode 100644 index 00000000000..68ac29c9eac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce3.C @@ -0,0 +1,15 @@ +// PR c++/69223 +// { dg-do compile { target c++11 } } + +template struct A +{ + T x[20]; +}; + +int main() +{ + auto l = [](const A& i){ return i; }; + A a; + + l(a); +} -- 2.30.2