This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/43641 (ICE on no-capture lambda returning reference or class)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 12 Apr 2010 16:08:03 -0400
- Subject: C++ PATCH for c++/43641 (ICE on no-capture lambda returning reference or class)
An oversight: build_cxx_call doesn't necessarily return a CALL_EXPR.
Fixed to use the same code that we used to use for thunks before they
moved into cgraph.
Tested x86_64-pc-linux-gnu, applied to trunk.
commit 708124b682e1fd33979e52a01f53711595e7a3f6
Author: Jason Merrill <jason@redhat.com>
Date: Mon Apr 12 11:41:28 2010 -0400
PR c++/43641
* semantics.c (maybe_add_lambda_conv_op): Use build_call_a and tweak
return value directly.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 66d152d..ea01eb3 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5968,9 +5968,12 @@ maybe_add_lambda_conv_op (tree type)
VEC_quick_push (tree, argvec, arg);
for (arg = DECL_ARGUMENTS (statfn); arg; arg = TREE_CHAIN (arg))
VEC_safe_push (tree, gc, argvec, arg);
- call = build_cxx_call (callop, VEC_length (tree, argvec),
- VEC_address (tree, argvec));
+ call = build_call_a (callop, VEC_length (tree, argvec),
+ VEC_address (tree, argvec));
CALL_FROM_THUNK_P (call) = 1;
+ if (MAYBE_CLASS_TYPE_P (TREE_TYPE (call)))
+ call = build_cplus_new (TREE_TYPE (call), call);
+ call = convert_from_reference (call);
finish_return_stmt (call);
finish_compound_stmt (compound_stmt);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv4.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv4.C
new file mode 100644
index 0000000..6584d28
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv4.C
@@ -0,0 +1,13 @@
+// PR c++/43641
+// { dg-options "-std=c++0x" }
+
+struct B
+{
+ int i;
+};
+
+void func()
+{
+ [](const B& b) -> const int& { return b.i; };
+ [](const B& b) { return b; };
+}