From patchwork Fri Jun 9 15:39:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 70829 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7501B3856962 for ; Fri, 9 Jun 2023 15:40:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7501B3856962 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686325216; bh=S5YeqkI19OTAl0PxAX1MIhcyV0s83ub6udnVefL4J84=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mMjbFA6RVg7EqqxxV28mHwg2BokRYCzpngHS2UbvtSSZNS7/3iq2LCkQPOapYlgv8 N3ISJpUH1F5TPR/eZA0sXPaJ8BaTDQ88XFP0s+q+osLAuYz9BC5tpiCR56+S7ChWYb 2y1ZOgu5OIxBfQcZTiU70V4XICZRCTdGUF9lF+Vw= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id B83FD385661B for ; Fri, 9 Jun 2023 15:39:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B83FD385661B Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-HTieowJSOzOjYcty0xZBMw-1; Fri, 09 Jun 2023 11:39:47 -0400 X-MC-Unique: HTieowJSOzOjYcty0xZBMw-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6260b40eac6so16548496d6.0 for ; Fri, 09 Jun 2023 08:39:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686325186; x=1688917186; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S5YeqkI19OTAl0PxAX1MIhcyV0s83ub6udnVefL4J84=; b=XOOK+ey+LjdKVBTOtIOkhl/iwjCFGy2uP0lYyXwCJcAxyd1PI4o34vRkqY6C+vwg1Q QTXO/Tu09xxyRXrKsRP/IxzUQQIHEYU790SnHuyzoms3kBf/YPvbjKo32Zx3G9QQsKO0 s/a8snIGVBGbm9aPBru6jnsRgaJ+mvbq8xQsZgS5SqkR4kfnAWe75am0JoMe0in7z6Mf /zySAOW7JKXxidFE61eQbJyvckq2vFsmS5qD+0R02GPk0+NtUWdigEwms+F6j1KsCEib 8YIPGvqWtAROCBBtNForwEgvcL43og5tZQfRfEcUYn5OSUk5zU4iU5KGJNUN8Bq+dW9A GdMQ== X-Gm-Message-State: AC+VfDwlBztVDY9DrdtU+FIEGvZq2x5hOseD+RkBzIMDcD2zYNjKnZv7 taIg5L0Oh4P7+j+oVQt4wfnQ9oZeQN36KoP2uoS2TPM6PNK5WpAFDgcbG3nRXgVULtBbo8++i0W 5O/M4cjuaNR677FkqYHqr4WVmCyOf0Ci+6wkaUQr9PgI8Jl5uK/uo5OSjkXXEGst125ieuhs/bA == X-Received: by 2002:a05:6214:5186:b0:626:2dec:e357 with SMTP id kl6-20020a056214518600b006262dece357mr6162174qvb.9.1686325186425; Fri, 09 Jun 2023 08:39:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5s7xxJvOFPDiBM6v/H1f3G0GoVvJ0TunNsJ57IG2yn3H3IsZGb10Webgi4IEFv5Kzb5EP/sQ== X-Received: by 2002:a05:6214:5186:b0:626:2dec:e357 with SMTP id kl6-20020a056214518600b006262dece357mr6162149qvb.9.1686325185950; Fri, 09 Jun 2023 08:39:45 -0700 (PDT) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id y13-20020a0cec0d000000b005dd8b934579sm1234883qvo.17.2023.06.09.08.39.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 08:39:45 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: init-list of uncopyable type [PR110102] Date: Fri, 9 Jun 2023 11:39:43 -0400 Message-Id: <20230609153943.3386685-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 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_NONE, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- The maybe_init_list_as_range optimization is a form of copy elision, but we can only elide well-formed copies. PR c++/110102 gcc/cp/ChangeLog: * call.cc (maybe_init_list_as_array): Check that the element type is copyable. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-opt1.C: New test. --- gcc/cp/call.cc | 8 ++++++++ gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C base-commit: 3e12669a0eb968cfcbe9242b382fd8020935edf8 diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index d6154f1a319..354773f00c6 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -4272,6 +4272,14 @@ maybe_init_list_as_array (tree elttype, tree init) if (has_non_trivial_temporaries (first)) return NULL_TREE; + /* We can't do this if copying from the initializer_list would be + ill-formed. */ + tree copy_argtypes = make_tree_vec (1); + TREE_VEC_ELT (copy_argtypes, 0) + = cp_build_qualified_type (elttype, TYPE_QUAL_CONST); + if (!is_xible (INIT_EXPR, elttype, copy_argtypes)) + return NULL_TREE; + init_elttype = cp_build_qualified_type (init_elttype, TYPE_QUAL_CONST); tree arr = build_array_of_n_type (init_elttype, CONSTRUCTOR_NELTS (init)); arr = finish_compound_literal (arr, init, tf_none); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C new file mode 100644 index 00000000000..56de4bc0092 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-opt1.C @@ -0,0 +1,15 @@ +// PR c++/110102 +// { dg-do compile { target c++11 } } + +// { dg-error "deleted|construct_at" "" { target *-*-* } 0 } + +#include + +struct A { + A(int) {} + A(const A&) = delete; // { dg-message "declared here" } + A(A&&) {} +}; +int main() { + std::list v = {1,2,3}; +}