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 <ja...@redhat.com>
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 <typename T>
+class A
+{
+ typename T::type b(); // { dg-error "int" }
+};
+
+template <typename T, typename U>
+void waldo(T, U) {}
+
+template <typename T>
+void bar()
+{
+ waldo([](A<T> a){ return a; },
+ []{});
+}
+
+int main()
+{
+ bar<int>();
+}
+
+// { dg-prune-output "used but never defined" }