From patchwork Fri Mar 8 15:54:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 226160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B69802C0389 for ; Sat, 9 Mar 2013 02:55:30 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1363362932; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=340zogD 5CQtwnNSok7e4OGcI/Ig=; b=lrnUZ7sbVmGIdnFJ7yta/H4z3opWuKPnoPAX4dS +YzHUmtyn6AeQjd4hpK3A2+0Wb8b0SlaXyNJw6MInA+hvtk1Sa7M+TQ+rx4GmLBm 5K0JH7w3a28G+/HLnbi1UeGioviNqczzZr712fcHFedgWmuAY2Yl3fWdc+SdY6+3 J5Ng= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Bn+SBgGSPJgpzl8c/iMdiK5G6rkaQqSz3ObDnxAR79z+LRgU11FYsVRZ2x0T/D nJNDrJjknx60YXbT0UIhDHBgQ1ddyQaEX4aL0+KNO0JCsrCPU8vWZZFPhwbY/BRd ACUxkUzUw4Aji0+MsfZexvtLVeyit7c+iUiblQck57EwY=; Received: (qmail 5237 invoked by alias); 8 Mar 2013 15:55:14 -0000 Received: (qmail 5204 invoked by uid 22791); 8 Mar 2013 15:55:13 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Mar 2013 15:55:02 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r28Ft1FW023072 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 8 Mar 2013 10:55:02 -0500 Received: from [10.3.113.56] (ovpn-113-56.phx2.redhat.com [10.3.113.56]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r28FsxWY015017 for ; Fri, 8 Mar 2013 10:55:01 -0500 Message-ID: <513A09D3.5020900@redhat.com> Date: Fri, 08 Mar 2013 10:54:59 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56567 (ICE with lambda returning init-list) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. commit 10c6627ac3371930fe44868ad94cb2ebc9d4e908 Author: Jason Merrill 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 + +int main() +{ + []{ return { 1, 2 }; }(); // { dg-error "initializer_list" } +} + +// { dg-prune-output "return-statement with a value" }