* C++ PATCH for c++/56567 (ICE with lambda returning init-list)
@ 2013-03-08 15:55 Jason Merrill
2013-03-11 16:20 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2013-03-08 15:55 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 319 bytes --]
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.
[-- Attachment #2: 56567.patch --]
[-- Type: text/x-patch, Size: 1238 bytes --]
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" }
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH for c++/56567 (ICE with lambda returning init-list)
2013-03-08 15:55 C++ PATCH for c++/56567 (ICE with lambda returning init-list) Jason Merrill
@ 2013-03-11 16:20 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2013-03-11 16:20 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 606 bytes --]
On 03/08/2013 10:54 AM, Jason Merrill wrote:
> 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.
As pointed out in the PR, this approach was wrong because it's possible
to have an expression with std::initializer_list type; the thing
returned might not have itself been a brace-enclosed init list. So
let's catch that earlier.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 56567-2.patch --]
[-- Type: text/x-patch, Size: 1706 bytes --]
commit 3d3cc430920cbb17be4e85742c34d51b94537a37
Author: Jason Merrill <jason@redhat.com>
Date: Mon Mar 11 12:03:31 2013 -0400
PR c++/56567
* typeck.c (check_return_expr): Disallow returning init list here.
* semantics.c (apply_deduced_return_type): Not here.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 233765a..e909b98 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9061,12 +9061,6 @@ 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/cp/typeck.c b/gcc/cp/typeck.c
index 58295d7..58ebcc0 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8136,6 +8136,11 @@ check_return_expr (tree retval, bool *no_warning)
"deduced to %<void%>");
type = error_mark_node;
}
+ else if (retval && BRACE_ENCLOSED_INITIALIZER_P (retval))
+ {
+ error ("returning initializer list");
+ type = error_mark_node;
+ }
else
{
if (!retval)
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C
index 029287b..f7b82ef 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist3.C
@@ -5,7 +5,7 @@
int main()
{
- []{ return { 1, 2 }; }(); // { dg-error "initializer_list" }
+ []{ return { 1, 2 }; }(); // { dg-error "initializer.list" }
}
// { dg-prune-output "return-statement with a value" }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-03-11 16:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-08 15:55 C++ PATCH for c++/56567 (ICE with lambda returning init-list) Jason Merrill
2013-03-11 16:20 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).