From patchwork Thu May 23 03:21:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH for c++/56915 (ICE after error with lambda) X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 245800 Message-Id: <519D8B2F.8040308@redhat.com> To: gcc-patches List Date: Wed, 22 May 2013 23:21:19 -0400 From: Jason Merrill List-Id: If we run into an error during template instantiation, we try to avoid starting more instantiations in order to limit the error cascade. If as a result of this we decide not to instantiate a lambda call operator, we shouldn't try to generate a conversion operator. Tested x86_64-pc-linux-gnu, applying to trunk. commit 84548604f1d5b2f175babe2fa3501ed14cec2db4 Author: Jason Merrill Date: Tue May 21 17:24:16 2013 -0400 PR c++/56915 * semantics.c (maybe_add_lambda_conv_op): Give up if the call op isn't defined. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 92a4917..5b36337 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9784,6 +9784,13 @@ maybe_add_lambda_conv_op (tree type) if (processing_template_decl) return; + if (DECL_INITIAL (callop) == NULL_TREE) + { + /* If the op() wasn't instantiated due to errors, give up. */ + gcc_assert (errorcount || sorrycount); + return; + } + stattype = build_function_type (TREE_TYPE (TREE_TYPE (callop)), FUNCTION_ARG_CHAIN (callop)); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template11.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template11.C new file mode 100644 index 0000000..520b804 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template11.C @@ -0,0 +1,25 @@ +// PR c++/56915 +// { dg-require-effective-target c++11 } + +template +class A +{ + typename T::type b(); // { dg-error "int" } +}; + +template +void waldo(T, U) {} + +template +void bar() +{ + waldo([](A a){ return a; }, + []{}); +} + +int main() +{ + bar(); +} + +// { dg-prune-output "used but never defined" }