From patchwork Mon Jan 30 19:10:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 50438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2349621wrn; Mon, 30 Jan 2023 11:11:44 -0800 (PST) X-Google-Smtp-Source: AK7set93FS6G0VOK/PRA6NXvkMjGisiGnxTu/16yYMbbqqG4K2htMYAI29A25fZPD/VYJfMol527 X-Received: by 2002:a17:907:62a1:b0:87a:3aff:cffa with SMTP id nd33-20020a17090762a100b0087a3affcffamr17699872ejc.27.1675105904259; Mon, 30 Jan 2023 11:11:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675105904; cv=none; d=google.com; s=arc-20160816; b=uhTeRJ951zRNPnSd1Ba/twhlNwxflsVueb/JGC5upitwcx8yLAj4dByzun5/uwC6kZ Pb+IiKFjDJo7/fUpbOCsIUvb4kblaT4HeT4wPGLOweNv2z98JTY4oePXXR9jCe93RckB AkWD+2MteENwGHRsRTJ+GFl30T2B245VSh6CH7mM06xVDvAXLqHqrldSy6GZZ/Au9UPS cao4hrxILG05S3DRJNsoBTdS9rDjURuVLUfS8XeImS9e0/T7o3DswbA8MUz0vHazS4DC Eb815L6OlMVPacfaAQdhajNeY2tRrRmqqSkA6bcR70sHMkKm2y6nVq5iUp7rNlFWaQ7A rnUA== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=wbHc6bH/k5KfdxDYSxGRIboE4xm7F62JIgX0KKro224=; b=Dc/tHQiv5bgesJnUXn354ttkBzDFdJbZANDh3RxIqUmUTDCE6qQcMRQH+VKRM2Jihl IHTZisAv3EGlNvfc1WBPm5paUuCL9qGhJAaPK//H1H+qRbVtsH/gt6D7o/8ifc8I0VNB AtF95ibxcYwVHXyKBmvrDqBYZKWmg/VCI4bx6VINAFETBnDTrB3lLWf4c/MWg2SCLYO8 ifOIHTSu7n3hXOomiwCh681ghE/E5odFkrxu/cbo6+6GgCs5sAAkFx5NjMyySgd5qwE5 kwaYMT/WPwPq+IKPd2pWBQ7gTPb3nmuryTQYxtfjIq5WYJv+zeV4+s7V9pEPkLrP1SCX OoQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="emD/dxdZ"; 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 y8-20020a50eb08000000b004a24e51305esi2551637edp.111.2023.01.30.11.11.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 11:11:44 -0800 (PST) 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="emD/dxdZ"; 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 129E53858C2F for ; Mon, 30 Jan 2023 19:11:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 129E53858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675105903; bh=wbHc6bH/k5KfdxDYSxGRIboE4xm7F62JIgX0KKro224=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=emD/dxdZzmi4qQiq7mYaOQZJaZJsCLs8LSiDo2Vitqxr5lxqRlS/1A9Zh9+4ZIxsm La8rUf/sOYizDfnO+vQjONVBXJpyd4OI/yxIMAOPisGkRYA0Ez5hBlnVUxE/c/x5rm Q140nf/bDzldbjoiwq0EumnojJ6EfvbCU6vQZ3dM= 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 5C81C3858C20 for ; Mon, 30 Jan 2023 19:10:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C81C3858C20 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-649-03IffokYM_WqVjOcE20UYQ-1; Mon, 30 Jan 2023 14:10:42 -0500 X-MC-Unique: 03IffokYM_WqVjOcE20UYQ-1 Received: by mail-qk1-f199.google.com with SMTP id x7-20020a05620a098700b007242aa494ddso875798qkx.19 for ; Mon, 30 Jan 2023 11:10:42 -0800 (PST) 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:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wbHc6bH/k5KfdxDYSxGRIboE4xm7F62JIgX0KKro224=; b=uBeEq/4kiFdnZSzGE5XKccdaNx14+WURMa4sPq0CYBJA+iYtLvnsKsb1g3ZWE+Et8J Jlnr2CShRxWEj0oUV6QH0NTNBNOhtWAK+x8lxhEUcwudxVzZCI2d0LwdW/SVyIjEmOPs L7aRZBW5peLrq81CC12xL7rd+eX5iqKNCN37BtZZyjN8kzzhUx45wTg7zNWpp2GK438K 4O5H5fV6k1mF0hVuKBy+7WJgqMRmnNoJNORXBv0UZR17Lb99zYzl+xZmEaiG8q0lPyEL 2zwO1+Y37hnkqz20n77FPGezN27HmESKijIvj0XccWuHqBR84+P6grLiIO2+qzIroE7X 82pQ== X-Gm-Message-State: AFqh2kpbVNVS2m6AUJpLMPutfe7L33c2FWOu+TwIcRDbozGrh864aYRF DSkdjnCosiuJUJv3sQmCUr8RIdNOt6lPvaT4hL93yNLkgUfnavSsQMUxRG7vYe9UJueYFghpfxa NpVkxvjX2zI6SyuGqoG9FkKlhHaOcGXKjD6J8ZLNy1NT/dnc+6SrEAfKwtDzgxrzXKV4= X-Received: by 2002:ad4:5c46:0:b0:536:ba5e:6a8d with SMTP id a6-20020ad45c46000000b00536ba5e6a8dmr72512813qva.22.1675105841077; Mon, 30 Jan 2023 11:10:41 -0800 (PST) X-Received: by 2002:ad4:5c46:0:b0:536:ba5e:6a8d with SMTP id a6-20020ad45c46000000b00536ba5e6a8dmr72512767qva.22.1675105840744; Mon, 30 Jan 2023 11:10:40 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id x14-20020a05620a258e00b0071b368cf074sm5047785qko.118.2023.01.30.11.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 11:10:40 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: excessive satisfaction in check_methods [PR108579] Date: Mon, 30 Jan 2023 14:10:38 -0500 Message-Id: <20230130191038.2450035-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.1.367.g5cc9858f1b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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, RCVD_IN_MSPIKE_H2, 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka 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?1756475848603268479?= X-GMAIL-MSGID: =?utf-8?q?1756475848603268479?= In check_methods we're unnecessarily checking satisfaction for all constructors and assignment operators, even those that don't look like copy/move special members. In the testcase below this manifests as an unstable satisfaction error because the satisfaction result is first determined to be false during check_methods (since A is incomplete at this point) and later true after completion of A. This patch fixes this simply by swapping the order of the constraint_satisfied_p and copy_fn_p / move_fn_p tests. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? This doesn't fix the regression completely, since we get a similar unstable satisfaction error if one of the constrained members is actually a copy/move special member. I suppose we need to rearrange things in finish_struct_1 so that check_methods gets called in a complete class context? PR c++/108579 gcc/cp/ChangeLog: * class.cc (check_methods): Test constraints_satisfied_p after testing copy_fn_p / move_fn_p instead of beforehand. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-pr108579.C: New test. --- gcc/cp/class.cc | 16 ++++++++-------- gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index 351de6c5419..d3ce8532d56 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -4822,11 +4822,11 @@ check_methods (tree t) /* 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)) + else if (copy_fn_p (fn) + && constraints_satisfied_p (fn)) TYPE_HAS_COMPLEX_COPY_CTOR (t) = true; - else if (move_fn_p (fn)) + else if (move_fn_p (fn) + && constraints_satisfied_p (fn)) TYPE_HAS_COMPLEX_MOVE_CTOR (t) = true; } @@ -4836,11 +4836,11 @@ check_methods (tree t) /* 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)) + else if (copy_fn_p (fn) + && constraints_satisfied_p (fn)) TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true; - else if (move_fn_p (fn)) + else if (move_fn_p (fn) + && constraints_satisfied_p (fn)) TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = true; } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C new file mode 100644 index 00000000000..bc7d709f889 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr108579.C @@ -0,0 +1,14 @@ +// PR c++/108579 +// { dg-do compile { target c++20 } } + +template +struct A { + A(double, char); + A(int) requires requires { A(0.0, 'c'); }; + A& operator=(int) requires requires { A(1.0, 'd'); }; +}; + +int main() { + A x(3); + x = 5; +}