Patchwork C++ PATCH for c++/56567 (ICE with lambda returning init-list)

login
register
mail settings
Submitter Jason Merrill
Date March 8, 2013, 3:54 p.m.
Message ID <513A09D3.5020900@redhat.com>
Download mbox | patch
Permalink /patch/226160/
State New
Headers show

Comments

Jason Merrill - March 8, 2013, 3:54 p.m.
My initial proposal for allowing general return type deduction allowed 
deduction of std::initializer_list, which is not permitted by C++11. 
But this doesn't make sense, because the underlying array will 
immediately leak, so we should just give an error even in C++1y.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 10c6627ac3371930fe44868ad94cb2ebc9d4e908
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Mar 8 10:25:55 2013 -0500

    	PR c++/56567
    	* semantics.c (apply_deduced_return_type): Don't allow returning
    	std::initializer_list.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index f1eb9ba..5c93a25 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9061,6 +9061,12 @@  apply_deduced_return_type (tree fco, tree return_type)
   if (return_type == error_mark_node)
     return;
 
+  if (is_std_init_list (return_type))
+    {
+      error ("returning %qT", return_type);
+      return_type = void_type_node;
+    }
+
   if (LAMBDA_FUNCTION_P (fco))
     {
       tree lambda = CLASSTYPE_LAMBDA_EXPR (current_class_type);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C
new file mode 100644
index 0000000..029287b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C
@@ -0,0 +1,11 @@ 
+// PR c++/56567
+// { dg-require-effective-target c++11 }
+
+#include <initializer_list>
+
+int main()
+{
+  []{ return { 1, 2 }; }();	// { dg-error "initializer_list" }
+}
+
+// { dg-prune-output "return-statement with a value" }