From patchwork Sun May 15 16:28:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1631194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Akbgv0b1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L1SVy2HtQz9s5V for ; Mon, 16 May 2022 02:28:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00D943857419 for ; Sun, 15 May 2022 16:28:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00D943857419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652632118; bh=Jf6i5fEBINnHHaTi/REjgz8LE+UTqTJ9IpvbaSqP1PY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Akbgv0b1/tR7aa/xHXCip/hUclIvu6J8LD9tLMJW90EMSNKSsw4aCj7e3Xu8LNw0b B/Foc5YQT4HY7Qg6J6/NwI7Aa+ZvmyrWA+w+WAdfRO2wqlBuW3mA2CwZ93gFlAyTcA Ubqc8FCjrEKELSoX8mQjSEMrp0/xszNgjeaOw8e4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id DCF353858D32 for ; Sun, 15 May 2022 16:28:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DCF353858D32 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-30-uH-LeEROMOC2SXVUcOJMKg-1; Sun, 15 May 2022 12:28:16 -0400 X-MC-Unique: uH-LeEROMOC2SXVUcOJMKg-1 Received: by mail-qt1-f200.google.com with SMTP id o16-20020ac87c50000000b002f3b8cd6a7fso10029159qtv.13 for ; Sun, 15 May 2022 09:28:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Jf6i5fEBINnHHaTi/REjgz8LE+UTqTJ9IpvbaSqP1PY=; b=R4sLtKi2AZgbjlvtnJi5BRBPdfZIRgY+MqCyXh8Qt0EZAx6Hy6fAaUvZq7h6XU3D7v qiV0XCsLQe8He69Bj+GnG4TPP0NNyfpMQ8p0voh+eFICp1R57Fa6nxEAmU/mVBziPyoV fk4qyEbt8D1bMuAMzQOYhrPnGJ0VDKs1VYh3HouwsxDI+wX6fosUG8TsYz12zXJGyjBe ByjnHnj756VEQDTv8DGS518BNdsW+zKLRqUw7LehXacD5liZqznWMeRX+z5VpLAu4OYe EsOwuOl1dVuwcmSvXbyoCMQZ6/5e0snoLjmbtb/3fk3nvyLzf4uayTu0qgytw2OYlnr3 Rqdw== X-Gm-Message-State: AOAM531e+OjmVmEVv6ihvBuIxPc09LtyZ5YlfqYw5kLcgIuDjSIpSsI4 g+fCxGRUQ39f0ZigxNF+9E2+c3IzbUnvs+G0PdqZ3436gxV6w5CCjXemfiVzjbdbmLeTfBfuKY5 N+R7gQIzVXXrIwYL/vrDhDLztPignKrCTEvrVbhDgnN8bJZZEdGmYbaWbMfChHVjsBQ== X-Received: by 2002:a05:6214:2024:b0:45a:8c17:9e68 with SMTP id 4-20020a056214202400b0045a8c179e68mr12395071qvf.91.1652632095264; Sun, 15 May 2022 09:28:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL7gYd3klwXuF0bMVwtAbpp8HA7jUR3xAPbp++89DFgDDTxpIdEPUuQewG+aWC4msn8NW18g== X-Received: by 2002:a05:6214:2024:b0:45a:8c17:9e68 with SMTP id 4-20020a056214202400b0045a8c179e68mr12395050qvf.91.1652632094794; Sun, 15 May 2022 09:28:14 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id z17-20020ac84551000000b002f39b99f689sm4932055qtn.35.2022.05.15.09.28.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 May 2022 09:28:14 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: array {}-init [PR105589] Date: Sun, 15 May 2022 12:28:12 -0400 Message-Id: <20220515162812.3970024-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" My patch for 105191 made us use build_value_init more frequently from build_vec_init_expr, but build_value_init doesn't like to be called to initialize a class in a template. That's caused trouble in the past, and seems like a strange restriction, so let's fix it. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/105589 PR c++/105191 PR c++/92385 gcc/cp/ChangeLog: * init.cc (build_value_init): Handle class in template. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-array16.C: New test. --- gcc/cp/init.cc | 7 +++---- gcc/testsuite/g++.dg/cpp0x/initlist-array16.C | 11 +++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array16.C base-commit: c5397682aff4ae9ced15ddc74971b9b6e218b664 diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index f1ed9336dc9..a4a0a0ac0c2 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -343,10 +343,6 @@ build_value_init (tree type, tsubst_flags_t complain) A program that calls for default-initialization or value-initialization of an entity of reference type is ill-formed. */ - /* The AGGR_INIT_EXPR tweaking below breaks in templates. */ - gcc_assert (!processing_template_decl - || (SCALAR_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)); - if (CLASS_TYPE_P (type) && type_build_ctor_call (type)) { tree ctor @@ -354,6 +350,9 @@ build_value_init (tree type, tsubst_flags_t complain) NULL, type, LOOKUP_NORMAL, complain); if (ctor == error_mark_node || TREE_CONSTANT (ctor)) return ctor; + if (processing_template_decl) + /* The AGGR_INIT_EXPR tweaking below breaks in templates. */ + return build_min (CAST_EXPR, type, NULL_TREE); tree fn = NULL_TREE; if (TREE_CODE (ctor) == CALL_EXPR) fn = get_callee_fndecl (ctor); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array16.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array16.C new file mode 100644 index 00000000000..bb1d8d84704 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array16.C @@ -0,0 +1,11 @@ +// PR c++/105589 +// { dg-do compile { target c++11 } } + +struct X { X(); }; + +struct array { X m[2]; }; + +template +void f() { + array w = array{}; +}