From patchwork Tue Mar 5 22:23:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1052016 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-497411-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="UH2+HWi0"; 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 44DWdg6f1Vz9s1B for ; Wed, 6 Mar 2019 09:24:05 +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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=TH9pFFbEyHIzjH8K0l1HyDK2G2qc7 Kd9LizLmEdqnb3fNleXMz4I4C8t8o2JeJ13HohNMf/ywpmTPi6e7+qDv4hIsXmuk 1EwxUFkK+buXCc2ak6ZhsALc70jpDCYJWb4ZrbHS8VnnftBLUa953IDnPZm3YKEL DSGuqfC52bE/+c= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=o1+LCrFmvlsh82GneE74trA64Os=; b=UH2 +HWi0uRXyTHlO8xBehPzdgi/PMy2wpXMWd3Gaj/BwoXLKT31fQqGmAIn6XsfsplP 9eplJiJNfERxyqn+z3cpV6ceZ3/sA0WSdtY/X75Ad1U+dI5AuVkpeAhksQBxjHoM P0885IMIcQlGZ7ciT416Nw7FKw4+bADNhMe8kzvw= Received: (qmail 89424 invoked by alias); 5 Mar 2019 22:23:58 -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 89413 invoked by uid 89); 5 Mar 2019 22:23:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ftype, sk:next_in, type_domain, TYPE_DOMAIN 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; Tue, 05 Mar 2019 22:23:57 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A0F06C0495A1 for ; Tue, 5 Mar 2019 22:23:55 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-64.ams2.redhat.com [10.36.117.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 37179608C1; Tue, 5 Mar 2019 22:23:55 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x25MNp67027900; Tue, 5 Mar 2019 23:23:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x25MNjQo027897; Tue, 5 Mar 2019 23:23:45 +0100 Date: Tue, 5 Mar 2019 23:23:45 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Allow value initialization of classes with flexible array member (PR c++/87148) Message-ID: <20190305222345.GE7611@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi! In this PR, Jonathan argues that we should accept value initialization of classes with flexible array member. The following patch does that. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-03-05 Jakub Jelinek PR c++/87148 * init.c (build_value_init_noctor): Ignore flexible array members. * g++.dg/ext/flexary34.C: New test. Jakub --- gcc/cp/init.c.jj 2019-03-05 15:34:17.164490227 +0100 +++ gcc/cp/init.c 2019-03-05 15:34:27.140327205 +0100 @@ -419,6 +419,15 @@ build_value_init_noctor (tree type, tsub if (ftype == error_mark_node) continue; + /* Ignore flexible array members for value initialization. */ + if (TREE_CODE (ftype) == ARRAY_TYPE + && !COMPLETE_TYPE_P (ftype) + && !TYPE_DOMAIN (ftype) + && COMPLETE_TYPE_P (TREE_TYPE (ftype)) + && (next_initializable_field (DECL_CHAIN (field)) + == NULL_TREE)) + continue; + /* We could skip vfields and fields of types with user-defined constructors, but I think that won't improve performance at all; it should be simpler in general just --- gcc/testsuite/g++.dg/ext/flexary34.C.jj 2019-03-05 15:31:38.731079324 +0100 +++ gcc/testsuite/g++.dg/ext/flexary34.C 2019-03-05 15:32:46.852966084 +0100 @@ -0,0 +1,10 @@ +// PR c++/87148 +// { dg-do compile } +// { dg-options "-pedantic" } + +struct Tst { int i; char t[]; }; // { dg-warning "forbids flexible array member" } + +Tst t {}; // { dg-warning "extended initializer lists only available with" "" { target c++98_only } } +Tst u = Tst(); +void foo () { Tst u = {}; } +Tst *bar () { return new Tst (); }