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: 63921 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 58D4C3858407 for ; Mon, 30 Jan 2023 19:11:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58D4C3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675105888; 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=qXn8j5Fef31Auk9FXh2PmwoDfvlcNkUUaYsAYmElAMs2EdbrpzRb1yJruIqfD0MvJ tdX5VLAJPMf1YM66KvegA2mZXGqP84CHdz0WJRIZPg+FvRNo1WgJbQQNWpYJV28On8 vqVScHqUxL28U+QikGReLo+3Sb87mCmyw88ictZE= 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-Google-Smtp-Source: AMrXdXvQKuGNgLMmgxgIblxkMfNLgzVji4NM1W+XyQo9jW6tEJEy255F5oLSQYjtY923L7Fb/Eo5vg== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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; +}