This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/43875 (ice on invalid lambda return)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 27 Apr 2010 17:05:17 -0400
- Subject: C++ PATCH for c++/43875 (ice on invalid lambda return)
We don't deduce std::initializer_list for a { } return value in a
lambda, but we shouldn't ICE either.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.5.
commit 5cf6419b078404ebd76dcfde4e7d93c23f7cdbf2
Author: Jason Merrill <jason@redhat.com>
Date: Fri Apr 23 19:10:19 2010 -0400
PR c++/43875
* semantics.c (lambda_return_type): Complain about
braced-init-list.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index ea01eb3..05c5168 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5521,6 +5521,11 @@ tree
lambda_return_type (tree expr)
{
tree type;
+ if (BRACE_ENCLOSED_INITIALIZER_P (expr))
+ {
+ warning (0, "cannot deduce lambda return type from a braced-init-list");
+ return void_type_node;
+ }
if (type_dependent_expression_p (expr))
{
type = cxx_make_type (DECLTYPE_TYPE);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce2.C
new file mode 100644
index 0000000..718d49c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce2.C
@@ -0,0 +1,7 @@
+// PR c++/43875
+// { dg-options "-std=c++0x" }
+
+int main()
+{
+ auto x2 = []{ return { 1, 2 }; }; // { dg-message "return" }
+}