From patchwork Fri Dec 12 17:45:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 420611 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 264251400DE for ; Sat, 13 Dec 2014 04:45:32 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=lrbBXUlr80wRjtYH7OWDuS0WwhG8Q6/6MBwM5Qvf5o6iEF DfYMowUv0pnYM4VtvKz43IypVhTx7cCXSzBO2P/C/Xh1m5KIAOjjKz/VKF5Q0sQb 8BqaJDh5UWTg/eQmSRu3AA7ZidaJnWKOSpdQ92oCRehePuq+CURkn/TXe7vlc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=FDLWfzLiB3R4lg2aUOA37bZSwws=; b=gIjzg56T4AjPUc5rbkla 3IkSYW6jVILgJlfh9cfRnMjh7Feh3Rpi0+K1kGUbRKz9J79P5l4XORv01RSQeAFs 4rhh972THsqXxRgXREA2WhfzgHpF5lhjtp+OGQHDSjuHx+uxkMB0smxOhun9EPha bmuZEOYyPLpvSI07KhFwy3Q= Received: (qmail 12869 invoked by alias); 12 Dec 2014 17:45:23 -0000 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 Received: (qmail 12822 invoked by uid 89); 12 Dec 2014 17:45:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 12 Dec 2014 17:45:17 +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 sBCHjGev017026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 12 Dec 2014 12:45:16 -0500 Received: from [10.10.116.25] ([10.10.116.25]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBCHjFik032269 for ; Fri, 12 Dec 2014 12:45:16 -0500 Message-ID: <548B29A7.9050105@redhat.com> Date: Fri, 12 Dec 2014 12:45:11 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for N3922 (direct-initialization from { x }) N3922 changed Unicorn initialization such that while copy-list-initialization of an auto variable still deduces std::initializer_list, direct-list-initialization from a list with a single element deduces the type of the element and from a list with multiple elements is ill-formed. I've made the ill-formed case a permerror to help with transition for affected code (if there is any). Tested x86_64-pc-linux-gnu, applying to trunk. commit bd12f74cb9c8258307883bf07daeeae5305cad34 Author: Jason Merrill Date: Fri Jun 20 14:22:26 2014 +0200 N3922 * pt.c (do_auto_deduction): In direct-init context, { x } deduces from x. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index efc2001..5ed9b2c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5546,6 +5546,8 @@ reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p, of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is a CONSTRUCTOR (with a record type). */ if (TREE_CODE (init) == CONSTRUCTOR + /* Don't complain about a capture-init. */ + && !CONSTRUCTOR_IS_DIRECT_INIT (init) && BRACE_ENCLOSED_INITIALIZER_P (init)) /* p7626.C */ { if (SCALAR_TYPE_P (type)) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d8a9c5b..8a663d9 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22117,7 +22117,21 @@ do_auto_deduction (tree type, tree init, tree auto_node) initializer is a braced-init-list (8.5.4), with std::initializer_list. */ if (BRACE_ENCLOSED_INITIALIZER_P (init)) - type = listify_autos (type, auto_node); + { + if (!DIRECT_LIST_INIT_P (init)) + type = listify_autos (type, auto_node); + else if (CONSTRUCTOR_NELTS (init) == 1) + init = CONSTRUCTOR_ELT (init, 0)->value; + else + { + if (permerror (input_location, "direct-list-initialization of " + "% requires exactly one element")) + inform (input_location, + "for deduction to %, use copy-" + "list-initialization (i.e. add %<=%> before the %<{%>)"); + type = listify_autos (type, auto_node); + } + } init = resolve_nondeduced_context (init); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-n3922.C b/gcc/testsuite/g++.dg/cpp0x/initlist-n3922.C new file mode 100644 index 0000000..4dadfc9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-n3922.C @@ -0,0 +1,15 @@ +// N3922 +// { dg-do compile { target c++11 } } + +#include +template struct same_type; +template struct same_type {}; + +auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list +same_type> s1; +auto x4 = { 3 }; // decltype(x4) is std::initializer_list +same_type> s4; +auto x5{ 3 }; // decltype(x5) is int +same_type s5; +auto x2 = { 1, 2.0 }; // { dg-error "initializer_list" } cannot deduce element type +auto x3{ 1, 2 }; // { dg-error "one element" } not a single element diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init5.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init5.C index 5976de0..1b287a1 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-init5.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init5.C @@ -6,5 +6,5 @@ int main() { if ([x(42)]{ return x; }() != 42) __builtin_abort(); - if ([x{1,2}]{ return x.begin()[0]; }() != 1) __builtin_abort(); + if ([x{24}]{ return x; }() != 24) __builtin_abort(); }