From patchwork Tue Jan 4 18:01:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1575336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=M7J3Qywk; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JT0mn151Bz9sPC for ; Wed, 5 Jan 2022 05:01:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 364D7385842D for ; Tue, 4 Jan 2022 18:01:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 364D7385842D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641319299; bh=6hvYm3NpIMNRMoH2T2VT3s1XCM+AMkyjDHiR4hIWZZY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=M7J3QywkLUaBq5H2BZKtw73xBWVbOVTNcSUG9giPLTuzo1/QQKd648wzRhj277u8j NGBBNiNQL9Z0qO3CSZa51i6PHK/yfb5X7FqiDGa0ORNUh25P8OZczo2Ciib/OSkd+S PyVMI/V9DFeIj5nlT4phWMFC5o/pkX2YIDId6+RA= 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 DAB423858C2C for ; Tue, 4 Jan 2022 18:01:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DAB423858C2C Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-155-fr9CgKpRPMODRcjFRkrapA-1; Tue, 04 Jan 2022 13:01:17 -0500 X-MC-Unique: fr9CgKpRPMODRcjFRkrapA-1 Received: by mail-qt1-f200.google.com with SMTP id a26-20020ac8001a000000b002b6596897dcso28742416qtg.19 for ; Tue, 04 Jan 2022 10:01:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6hvYm3NpIMNRMoH2T2VT3s1XCM+AMkyjDHiR4hIWZZY=; b=u0cnTEcPYbunrV4lCvZGg6ZrqBhEMFD3ERvI43bG42+XHz2pzdxB0m/C28q64IwpUT SVHd+Lp2EKZjHOXklvNg+eTy8fHCnQBgc+5B7WyHqs6mPH9sTFRo6l3LknDPnN99IISh HKAb6OjOkEgGoCTVf20n8Q4SfXjpOGPNt0GyAmaAVh/B+AOxz+StnWJT7yArnJWdspG3 QBjhng05C0sZLbvJw2/na5knx7soKknjphoL8Asc5QJ6rPESi78WNjv8LG5FztMyfGnX 2p5SyX+ameaQD0vuBCOBHizvaS8F894kcFIbP7tz+uydGP6jpU/fWwiTwoYVr1Wthi+n QHSQ== X-Gm-Message-State: AOAM5328IbewSMF4ijjV9xjUcAipWmaQdavFIFG2iBwOujevl4msVWn4 gud0urUuXPia9TZxk3OBVdoS6iER2DuH81g3edeNaKG3LFaDoUbfASjJlf0n5/CG7MvlhNYARc6 RzIXnL5IvhknVxxIgKFPZPssU6ygU4gUbvLmmSa6zhypM1w3ydux6Iqz5yXKV13i8pnw= X-Received: by 2002:ac8:4e4b:: with SMTP id e11mr46209692qtw.503.1641319276333; Tue, 04 Jan 2022 10:01:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+PsFfG6LChefZK5Iiya/F5M15lBMu9AS74UZv2XSvAQDjRJAu0maohrlCfL5JeZs9I3jbaA== X-Received: by 2002:ac8:4e4b:: with SMTP id e11mr46209566qtw.503.1641319275186; Tue, 04 Jan 2022 10:01:15 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id r23sm21801254qkk.24.2022.01.04.10.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 10:01:14 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: "more constrained" vs staticness of memfn [PR103783] Date: Tue, 4 Jan 2022 13:01:13 -0500 Message-Id: <20220104180113.141274-1-ppalka@redhat.com> X-Mailer: git-send-email 2.34.1.428.gdcc0cd074f MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.5 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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here we're rejecting the calls to g1 and g2 as ambiguous even though one overload is more constrained than the other (and otherwise equivalent), because the implicit 'this' parameter of the non-static overload causes cand_parms_match to think the function parameter lists aren't equivalent. This patch fixes this by making cand_parms_match skip over 'this' appropriately. Note that this bug only occurs with non-template member functions because for the template case more_specialized_fns seems to already skips over 'this' appropriately. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 11? PR c++/103783 gcc/cp/ChangeLog: * call.c (cand_parms_match): Skip over 'this' when given one static and one non-static member function. Declare static. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-memfun2.C: New test. --- gcc/cp/call.c | 17 ++++++++++--- gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 7f7ee88deed..ed74b907828 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -11918,7 +11918,7 @@ joust_maybe_elide_copy (z_candidate *&cand) /* True if the defining declarations of the two candidates have equivalent parameters. */ -bool +static bool cand_parms_match (z_candidate *c1, z_candidate *c2) { tree fn1 = c1->fn; @@ -11940,8 +11940,19 @@ cand_parms_match (z_candidate *c1, z_candidate *c2) fn1 = DECL_TEMPLATE_RESULT (t1); fn2 = DECL_TEMPLATE_RESULT (t2); } - return compparms (TYPE_ARG_TYPES (TREE_TYPE (fn1)), - TYPE_ARG_TYPES (TREE_TYPE (fn2))); + tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1)); + tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2)); + if (DECL_FUNCTION_MEMBER_P (fn1) + && DECL_FUNCTION_MEMBER_P (fn2) + && (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn1) + != DECL_NONSTATIC_MEMBER_FUNCTION_P (fn2))) + { + /* Ignore 'this' when comparing the parameters of a static member + function with those of a non-static one. */ + parms1 = skip_artificial_parms_for (fn1, parms1); + parms2 = skip_artificial_parms_for (fn2, parms2); + } + return compparms (parms1, parms2); } /* Compare two candidates for overloading as described in diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C new file mode 100644 index 00000000000..e3845e48387 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun2.C @@ -0,0 +1,25 @@ +// PR c++/103783 +// { dg-do compile { target c++20 } } + +template +struct A { + template void f1() = delete; + template static void f1() requires B; + + template void f2() requires B; + template static void f2() = delete; + + void g1() = delete; + static void g1() requires B; + + void g2() requires B; + static void g2() = delete; +}; + +int main() { + A a; + a.f1(); // OK + a.f2(); // OK + a.g1(); // OK, previously rejected as ambiguous + a.g2(); // OK, previously rejected as ambiguous +}