From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664478686; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LsBBFt+hct5CWNJ86qcHBGwu1V75CrY7DNCYAjw3K5I=; b=LeaNC5u+OMUi79nDhborgvJg/da27kQ8RXOdPCfIGVSuCk/qHGm52kOdGpZBc7Lod1hGcf biKmZy2jgrN2qfkrdOIwzzTbxsR7JPVIwkmUaz8C/C+B6QeJ5SQD1ilnhIcz8uHQnp1h7h YYDGQsUWhdqdI2ywTwvFYYonjFo61WE= 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-Google-Smtp-Source: AMsMyM5C4QQl5YkISFtyBDOsuzvgposZYFBw+uwfOv0r7QpzhDKQM1sVERrklAxp7JvbuYDrD2/LZQ== 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 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), "???" ); base-commit: 73d9b0e5947e162386f7e25d3851097cee1bb366 -- 2.31.1