From patchwork Thu Sep 29 19:11:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp132340wrs; Thu, 29 Sep 2022 12:12:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48PTe0W+sKo2Rdl0AoSizF9gRl0AnQqGQ2dSLqfIYVv0obbOsHFesWbAF+grfH51ct+O0E X-Received: by 2002:a05:6402:34cb:b0:451:61c9:a316 with SMTP id w11-20020a05640234cb00b0045161c9a316mr4879653edc.268.1664478733093; Thu, 29 Sep 2022 12:12:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664478733; cv=none; d=google.com; s=arc-20160816; b=tJ7EEfQ8o4zG5YwZl+ooXOFKVk0WfftQQYTfo/6E47tuwRv8K63t4HrzrAupQARToG Ev93cffCdpmWeHnnBNHe8v2tBBCHJIN2qR2NufX19IojGCOlRIRjArUc1bWuU5XlKwPr iuWany80cW7j4g3ITJtNL7YrJpC33PHCZ/bc8BJvoqGeQJ0A6TVmZ5K3lnQXGmw+Qk1U X82j0sB0aLCgefc5bllV8JDVK6qj6uXrGt1aAa4TO+aBNTqZloMqfQaNIMml2DY3E2kN XWzUG8lzBZi1wHj5VvDRilfhcT2sopGQTZW3dNSwfhoh93+zkTCWb3zNTc7I76XtVPjK 85Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=LsBBFt+hct5CWNJ86qcHBGwu1V75CrY7DNCYAjw3K5I=; b=P6gwuTZTXms45kGheAIvkq1FUG3Pcic0fAkx0cwOtBEYXwo54K09y+O6OUlmDKxQK3 FAhAutej0tUTd1WXaKIq+8u7qwwTbiCzMesAulbK7vgbgISy8bPUEhedyYoHcpIF6IKh x3PLvwq5ecPSGJ0muq1kA2GMXzFW18wXuyY+Yamm0blhtMBt0SNBasU+zs8UsuAwlRyC O5uX8hD8odfwtQmtX1BHJqnE1yP2bQO27wb1JBXvpUWv13OdhlbYpwGJX3T849PnmkS4 pEk3/TFdxpGGonaR+bQIb+ImF2XSMvhE4OPAZUsUdiWCNHwiLdFLeUmbZ0BCgWIbjfxU 7ong== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ExdZuoXh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x25-20020a50d619000000b00451d665e753si188470edi.499.2022.09.29.12.12.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 12:12:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ExdZuoXh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6681385C33F for ; Thu, 29 Sep 2022 19:12:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6681385C33F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664478731; bh=LsBBFt+hct5CWNJ86qcHBGwu1V75CrY7DNCYAjw3K5I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ExdZuoXh7yJ/9H5lTP3zJCw1IyFv8jDZl7wExpOJc1hiJHupatIRGu8uPW2/U2OVS 8K7GQ7Rq4eYC2qDgnBfjbFaArstaY9VlFtimHK+HuXjQ1802O7E2GSiON/HNTGB80h UYsKtXYGcY1kM+3n6mHFsi0OktpWhE51B12trjQI= 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 324643858C55 for ; Thu, 29 Sep 2022 19:11:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 324643858C55 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-221-XSycFvBLN16XylvIrzUpXw-1; Thu, 29 Sep 2022 15:11:24 -0400 X-MC-Unique: XSycFvBLN16XylvIrzUpXw-1 Received: by mail-qt1-f199.google.com with SMTP id j25-20020ac84c99000000b0035bb13ed4ffso1521584qtv.23 for ; Thu, 29 Sep 2022 12:11:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=LsBBFt+hct5CWNJ86qcHBGwu1V75CrY7DNCYAjw3K5I=; b=QzEzM6hc3COg5iCUkcacNVeC+xYIjDmB4YvSzq5Q5D2gF/hhw0nQcoDhueOSf+nckg fnV1wQRAAvdGf82YtsP3aY+8E5r4wU2NPMQi3dKXdJrWr1PMk5Ld7/h7C+6d95hHQOvA +wDQCi1n7gy7ihaHM5Ic7OVQPpzLDcsEmKU5hZzctpk8HpGpzWF02vCHch2c470o+jDU ZZ5KgvGYMgoWlQcpKgrBdLxq46pSqwM3NkS63+Bz+rZwq/NtjqD731P0FxDll4OWZUmj +0IxS3SAfmWl+uSAjJCBpv0KcIrlczEPgfrrVHDWrYLqdbzqb6j0toUZrhYmNT3Lenud sjYA== X-Gm-Message-State: ACrzQf0q2MCleifDSEb9N3wPzVm0MxI8DRTXjdhXEo8rLmktuWLkAR8K AYMSGqyo/zppV+5afYO7Yl/z5QdYAFmub+1MulCAbhtWGfqEwo80oQ0Zg78tn3YlWi3F8vCJCcg VLEKMpuIxChLrfuEhgwuFe/bz4c9f98O7IqSX4C9fayGPU5zyJIRPLoG0JwdASKZI8Q== X-Received: by 2002:ac8:7c46:0:b0:35d:147c:38ff with SMTP id o6-20020ac87c46000000b0035d147c38ffmr3828965qtv.1.1664478683983; Thu, 29 Sep 2022 12:11:23 -0700 (PDT) X-Received: by 2002:ac8:7c46:0:b0:35d:147c:38ff with SMTP id o6-20020ac87c46000000b0035d147c38ffmr3828935qtv.1.1664478683557; Thu, 29 Sep 2022 12:11:23 -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 h10-20020a05620a284a00b006bb83c2be40sm244495qkp.59.2022.09.29.12.11.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 12:11:23 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: fix triviality of class with unsatisfied op= Date: Thu, 29 Sep 2022 15:11:20 -0400 Message-Id: <20220929191120.1938729-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=-13.2 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 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745332451940141586?= X-GMAIL-MSGID: =?utf-8?q?1745332451940141586?= Tested x86_64-pc-linux-gnu, applying to trunk. -- >8 -- cxx20_pair is trivially copyable because it has a trivial copy constructor and only a deleted copy assignment operator; the non-triviality of the unsatisfied copy assignment overload is not considered. gcc/cp/ChangeLog: * class.cc (check_methods): Call constraints_satisfied_p. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/cond-triv3.C: New test. --- gcc/cp/class.cc | 13 ++++++-- gcc/testsuite/g++.dg/cpp2a/cond-triv3.C | 44 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/cond-triv3.C base-commit: 73d9b0e5947e162386f7e25d3851097cee1bb366 diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index b84f4227e7e..aebcb53739e 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -4795,8 +4795,9 @@ check_methods (tree t) /* Check whether the eligible special member functions (P0848) are user-provided. add_method arranged that the CLASSTYPE_MEMBER_VEC only - has the eligible ones; TYPE_FIELDS also contains ineligible overloads, - which is why this needs to be separate from the loop above. */ + has the eligible ones, unless none are eligible; TYPE_FIELDS also contains + ineligible overloads, which is why this needs to be separate from the loop + above. */ if (tree dtor = CLASSTYPE_DESTRUCTOR (t)) { @@ -4819,6 +4820,10 @@ check_methods (tree t) { if (!user_provided_p (fn)) /* Might be trivial. */; + else if (TREE_CODE (fn) == TEMPLATE_DECL) + /* Templates are never special members. */; + else if (!constraints_satisfied_p (fn)) + /* Not eligible. */; else if (copy_fn_p (fn)) TYPE_HAS_COMPLEX_COPY_CTOR (t) = true; else if (move_fn_p (fn)) @@ -4829,6 +4834,10 @@ check_methods (tree t) { if (!user_provided_p (fn)) /* Might be trivial. */; + else if (TREE_CODE (fn) == TEMPLATE_DECL) + /* Templates are never special members. */; + else if (!constraints_satisfied_p (fn)) + /* Not eligible. */; else if (copy_fn_p (fn)) TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true; else if (move_fn_p (fn)) diff --git a/gcc/testsuite/g++.dg/cpp2a/cond-triv3.C b/gcc/testsuite/g++.dg/cpp2a/cond-triv3.C new file mode 100644 index 00000000000..d0711cf2607 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/cond-triv3.C @@ -0,0 +1,44 @@ +// { dg-do compile { target c++20 } } + +template +struct X +{ + T first{}; + + X& operator=(const X&) = delete; + X& operator=(const X&) requires requires (T& t) { t = t; } { return *this; } +}; + +// C++20 std::pair: +using cxx20_pair = X; +static_assert( __is_trivially_constructible(cxx20_pair, const cxx20_pair&), "" ); +static_assert( !__is_assignable(cxx20_pair&, const cxx20_pair&), "" ); +static_assert( __is_trivially_copyable(cxx20_pair), "" ); + +template struct conditional { using type = F; }; +template struct conditional { using type = T; }; + +struct base +{ + base() = default; + ~base() = default; + base(const base&) = default; + base& operator=(const base&) = delete; +}; + +struct nope; + +template +struct Y : base +{ + T first{}; + + Y& operator=(typename conditional<__is_assignable(T&, const T&), const Y&, const nope&>::type) + { return *this; } +}; + +// C++17 std::pair: +using cxx17_pair = Y; +static_assert( __is_trivially_constructible(cxx17_pair, const cxx17_pair&), "" ); +static_assert( ! __is_assignable(cxx17_pair&, const cxx17_pair&), "" ); +static_assert( __is_trivially_copyable(cxx17_pair), "???" );