From patchwork Sat Mar 10 11:57:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 884139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-474539-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jkcwT0AP"; dkim-atps=neutral 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 3zz2nb59x5z9tbY for ; Sat, 10 Mar 2018 22:58:11 +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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=SMrnhmcB0q7PagmYOE2/ZD3PVMWK7W1zNSXnTabGjxgfarHfWUdeb xSlTC/7Dsv5YlXjkbfNCsNPkCNoQomhs+wbHkXgcm7C3Wzigr0jvGytWwLoSIDKG bbQDL/5fTcaKV91Sjcxmz4B4IVgn0EbHGicgz+NIXx5PawMvVscvGg= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=4/5VMhOPYhkVivA1Nkho4LdAxuE=; b=jkcwT0APZ0Xq0jMbCDjw pdi2xWyA4R8h00zTFix6XfO6QG615WwqsGAIJGiaznqvufmKMWY2RgL5ncLCxi8N tLAtXn4zmu25HFXgTJsQawUOdQ2ed+yOw+vMX2nF9dW3dYzxqpmXUIAIREOWui28 dwpRlUtCzJS8n/DtidWiOg0= Received: (qmail 70957 invoked by alias); 10 Mar 2018 11:57:57 -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 70848 invoked by uid 89); 10 Mar 2018 11:57:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= 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 ESMTP; Sat, 10 Mar 2018 11:57:54 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA1174E4C0 for ; Sat, 10 Mar 2018 11:57:53 +0000 (UTC) Received: from freie.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DD525C262 for ; Sat, 10 Mar 2018 11:57:53 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by freie.home (8.15.2/8.15.2) with ESMTP id w2ABvhwU366391; Sat, 10 Mar 2018 08:57:43 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PR c++/84729] convert new init to array elt type Date: Sat, 10 Mar 2018 08:57:43 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 A parenthesized initializer is only accepted when new()ing an array in permissive mode. We were not careful, however, to convert the TREE_LIST initializer to the array element type in this extension. This patch fixes it: after turning the TREE_LIST initializer to a compound_expr, we convert it to the base type. Regstrapped on i686- and x86_64-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/84729 * init.c (build_vec_init): Convert tree list to base type. for gcc/testsuite/ChangeLog PR c++/84729 * g++.dg/pr84729.C: New. --- gcc/cp/init.c | 10 ++++++++-- gcc/testsuite/g++.dg/pr84729.C | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr84729.C diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 15cee17c780c..cb62f4886e6d 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -4405,8 +4405,14 @@ build_vec_init (tree base, tree maxindex, tree init, else { if (TREE_CODE (init) == TREE_LIST) - init = build_x_compound_expr_from_list (init, ELK_INIT, - complain); + { + init = build_x_compound_expr_from_list (init, ELK_INIT, + complain); + init + = convert_for_initialization (NULL_TREE, type, init, + LOOKUP_IMPLICIT, ICR_INIT, + NULL_TREE, 0, complain); + } elt_init = (init == error_mark_node ? error_mark_node : build2 (INIT_EXPR, type, to, init)); diff --git a/gcc/testsuite/g++.dg/pr84729.C b/gcc/testsuite/g++.dg/pr84729.C new file mode 100644 index 000000000000..6ca7fb0032f5 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr84729.C @@ -0,0 +1,7 @@ +// { dg-do compile } +// { dg-options "-fpermissive" } + +typedef int b[2]; +void a() { + new b(a); // { dg-warning "parenthesized initializer in array new|invalid conversion" } +}