From patchwork Wed Sep 18 20:59:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 97679 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 6D6AC385C6D1 for ; Wed, 18 Sep 2024 21:00:34 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTP id C60C63858D28 for ; Wed, 18 Sep 2024 21:00:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C60C63858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C60C63858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726693205; cv=none; b=jPbpLIk2oM1XXBAdvKUuZeM7QXjrqdYBjB+QnOs8PH5XE2cxVnKvj7chd+HqXTtdO3WclgU2KxpRWFsPwwz/f1tTJa05pVlIJ2h8HDVJ8NGA211RIIU+HrWlwExoJdpzs3kaWSM8AzNzjP3iiurIm7X2gukYViP7WVN6YvJ87Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726693205; c=relaxed/simple; bh=00NYZY2Y1SNbnPbpY8KCNA1msgKrXpNBIgyW5f4shFo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=h/uk7mM91Ba4X1jSctlNJ70QWa86aU48rX7d5JkHd3LvhVsb6RqPHdTtamKndgxUpXMxPGCTafaq5Ia8zPLpIOHVQ2frFfn3QrGBQXX4bnqnn/eN09qcZ11TKxXt4+hV5wPLUks8NAraGvzYxfFEntwQkJR2zTH9LEB6uSQnfoA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726693203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=req0yzL+sFnxzyoIJSww4aG2AUD48kfzcyKOekMdddo=; b=EnZ3J+lEAr9zgbQ1DgvmJ2cXQDKlYiboPmfszU4PyJhcShBLk98/dghPkNgXr6QZYah6+o TFqmby+UneAD+vZJO/WZNgrVUdBTvPBXrex/xdkf1qOrN7rRV38S9rkunC7mvXsVpJWgGE 1lFTNXCZJoLN/SFMf0lU920o0ImYbOY= Received: from mail-vs1-f72.google.com (mail-vs1-f72.google.com [209.85.217.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-ckGwc566PnWJkh7Ee_QKvA-1; Wed, 18 Sep 2024 17:00:01 -0400 X-MC-Unique: ckGwc566PnWJkh7Ee_QKvA-1 Received: by mail-vs1-f72.google.com with SMTP id ada2fe7eead31-49bd8224836so10367137.3 for ; Wed, 18 Sep 2024 14:00:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693200; x=1727298000; 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=req0yzL+sFnxzyoIJSww4aG2AUD48kfzcyKOekMdddo=; b=gR5q7csNI0IXLne+GsdLuyVdJL2Xr35p5UNkySCpDSVpFOugExeVq/oiBdRYci3T1j Il7EDN7cLZsyUNB0fdcxetIQX/V5ECx4SN+BAm5q3ZQFOXjtgkHCN+ItfJjUa11EI/Ep lcl8LxeifrdvZXpt8R7vHeNkTOOpvf5tf2Iu/3aoJlaWRk1HS68p6So1f1QPNkkVmUn3 lDFds1JgSDR+KYyQmS3APgtDV3/r0o2MrnsuIeoPcsswWzTEInD99QwLiIWI+mENoBM4 V7ETx1dqU7YxzeCVlKd5V468uLHOB76xGxJaNcGDexNX2aHNu+ju/SLVMNxiohYdgZxz fFeQ== X-Gm-Message-State: AOJu0Yw3HuygYbwzE9WMlVKgYk2ODShnNDbBYqibY2qYqrHngWkMZkza Xv+KG5I7je6NpUT7PIKVVXQXKd0HMmH/drodT9umEv9DQwLftGBljRS+x+kgV/iPoGMTzzPCIA7 Ei1I0xz20KGYhAksZErDJlHB/PgZyTAsZI0qB7TWd0klDUCOL3vBTrbGeTLSC//zJpQEFvmj22s DqktAJ17snmlyRU87kVwbsGotqCTy/IMKHfiaM X-Received: by 2002:a05:6102:32d4:b0:49b:ef23:b3a2 with SMTP id ada2fe7eead31-49d415a7b5amr8178195137.7.1726693200073; Wed, 18 Sep 2024 14:00:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvrVWc892XpXsItU8bZe/a/f+gZ4SZ0ZKriU3i1ZHlgdSxfWjEyqa1H6pM15Ghwc8w4bQoJA== X-Received: by 2002:a05:6102:32d4:b0:49b:ef23:b3a2 with SMTP id ada2fe7eead31-49d415a7b5amr8178175137.7.1726693199630; Wed, 18 Sep 2024 13:59:59 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c75e44bf15sm1011446d6.11.2024.09.18.13.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 13:59:59 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 1/2] c++: CWG 2273 and non-constructors Date: Wed, 18 Sep 2024 16:59:45 -0400 Message-ID: <20240918205946.4082171-1-ppalka@redhat.com> X-Mailer: git-send-email 2.46.1.544.g3fb745257b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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_H3, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Our implementation of the CWG 2273 inheritedness tiebreaker seems to be incorrectly considering all inherited members, not just inherited constructors. This patch restricts the tiebreaker accordingly. DR 2273 gcc/cp/ChangeLog: * call.cc (joust): Restrict inheritedness tiebreaker to constructors. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/using1.C: Expect ambiguity for non-constructor call. * g++.dg/overload/using5.C: Likewise. --- gcc/cp/call.cc | 12 +++++------- gcc/testsuite/g++.dg/cpp1z/using1.C | 7 +++---- gcc/testsuite/g++.dg/overload/using5.C | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 3f753e2d2f9..87b54291b51 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -13350,13 +13350,11 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn, } } - /* F1 is a member of a class D, F2 is a member of a base class B of D, and - for all arguments the corresponding parameters of F1 and F2 have the same - type (CWG 2273/2277). */ - if (DECL_P (cand1->fn) && DECL_CLASS_SCOPE_P (cand1->fn) - && !DECL_CONV_FN_P (cand1->fn) - && DECL_P (cand2->fn) && DECL_CLASS_SCOPE_P (cand2->fn) - && !DECL_CONV_FN_P (cand2->fn)) + /* F1 is a constructor for a class D, F2 is a constructor for a base class B + of D, and for all arguments the corresponding parameters of F1 and F2 have + the same type (CWG 2273/2277). */ + if (DECL_P (cand1->fn) && DECL_CONSTRUCTOR_P (cand1->fn) + && DECL_P (cand2->fn) && DECL_CONSTRUCTOR_P (cand2->fn)) { tree base1 = DECL_CONTEXT (strip_inheriting_ctors (cand1->fn)); tree base2 = DECL_CONTEXT (strip_inheriting_ctors (cand2->fn)); diff --git a/gcc/testsuite/g++.dg/cpp1z/using1.C b/gcc/testsuite/g++.dg/cpp1z/using1.C index 1ed939d45fd..c7278ec880a 100644 --- a/gcc/testsuite/g++.dg/cpp1z/using1.C +++ b/gcc/testsuite/g++.dg/cpp1z/using1.C @@ -1,5 +1,4 @@ -// Test for hiding of used base functions when all the conversion sequences are -// equivalent, needed to avoid a regression on inherited default ctors. +// Test the CWG 2237 resolution doesn't apply to inherited non-constructors. struct A { @@ -17,7 +16,7 @@ struct B:A int main() { - B().f(1); // OK, derived f hides base f for single arg + B().f(1); // { dg-error "ambiguous" } B().f(1,2); // OK, base f can still be called with two args - B().g(1); // { dg-error "" } signatures differ, ambiguous + B().g(1); // { dg-error "ambiguous" } signatures differ } diff --git a/gcc/testsuite/g++.dg/overload/using5.C b/gcc/testsuite/g++.dg/overload/using5.C index ad17c78a561..0933a9f0fac 100644 --- a/gcc/testsuite/g++.dg/overload/using5.C +++ b/gcc/testsuite/g++.dg/overload/using5.C @@ -24,5 +24,5 @@ struct C: B { int main() { C c (42); - c.f(); + c.f(); // { dg-error "ambiguous" } } From patchwork Wed Sep 18 20:59:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 97680 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 C8FF33857000 for ; Wed, 18 Sep 2024 21:00:38 +0000 (GMT) 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 ESMTP id BE8A4385840E for ; Wed, 18 Sep 2024 21:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE8A4385840E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BE8A4385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726693208; cv=none; b=dT5aTulR7F4tUCaCnVrUhQ2zam/zgafs5IEZb/8gA8/maKNzoVhuqgqKytZi3nsO6FJvYouOz4lfhveqBmW0NbygDed573HeQOgML+YScEfQowf/Ch6awx8NsYGxpKPghFgzgB0jUxEDD0B+7UITOsUMnLZD9dN7ROHeY+YgrQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726693208; c=relaxed/simple; bh=UAIS/+pdKTjg5PZJSJkvBmwYSN4uo9a8hJ3NeMmQbNs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UYprhlrlw5ibMCQ+wjA14acvQNZe9tHfvhVzByEv8IZ6ccgZdpyqNSkMMmT9id9v2keqy9Znz2Uph8JW078rUJM7jepBNObpi3yzHktU1D5Hq8olPazwN9afoxHljMW+2oXMcknBIKhHjSnvrnJ1Tkn1RThW/my5mgm9w7JnVUo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726693205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lPAl/4Xw8K2y1FC6tzG+9r7GvtEdRgqXfTTfRbopMmw=; b=AoQr0GoWltsAf43NfUDNPT7+h/AzHxOncMRPej8KGR6Vm9x93obyXx2SU8rs+Yrr/8XF0Z phdkaztwURapbXLHNXtXULJOBPgAadjzYlPBEQ7CG5FIPgTisYeRpUGUn2LtFphPpwtJ35 GAD3nONeY4Fuuw5zFR45Ph/INy2xAnU= 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_256_GCM_SHA384) id us-mta-173-UtC1jqZSPDqsLebtArW4CQ-1; Wed, 18 Sep 2024 17:00:03 -0400 X-MC-Unique: UtC1jqZSPDqsLebtArW4CQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7a9a927e595so4576985a.1 for ; Wed, 18 Sep 2024 14:00:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693202; x=1727298002; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lPAl/4Xw8K2y1FC6tzG+9r7GvtEdRgqXfTTfRbopMmw=; b=d4H10wTplvxWv/I4CKQbA8oMweZ6tgIw1KeDIb7IAREAIn38bStGwh92KbSWtDn4/s wuaeuwjvD3JvIzgfNfohMz0PGU11TjiVbMhaqPJHWp2hUUlH/NF5NgdZIaiSuJy9ys61 T6yfNHEexuiHLLmEDviCsTyITBoD55iY6dFleMFQ8Y0atXEGQjIdwWrhu8hf7HjqmA52 hxXeo3MsqfiHqITcZV4laEUgdy/YblwSlG5wSyob/XSi9xIX0R+FTDCMtTYCIc7aPX0E YD/3yrzPRLUEEVGTuZyBFOaN4hQxzKX0/ehjBKJYUjxHcLwesFyxbQ0J0/UzP5NHJLH/ lEnw== X-Gm-Message-State: AOJu0Yy7qYcUjeR4QhHVgciQXY8+1c1b8epY/vhVlBdCldUc9ZU3EvCL 5dQaL8jSqORwgRJJJsxewMUIjsZHrwXLay+3KHW2rvoZhOXtYFrQ2mm+DYtnjdxqLRpeJiRLE2f 9V2z/O41jQGiw6ySXK1oLZ/iX4knwD88P7nhAvCpASpPbyCtwd3eMr0rs4/2/rfTSdlvF1SweZK vQ7m5otG+CcxqEI9VaGJ6OYjPfNzaQs9VPukZk X-Received: by 2002:a05:6214:230b:b0:6c5:3338:45d7 with SMTP id 6a1803df08f44-6c573801fc6mr150921026d6.12.1726693202444; Wed, 18 Sep 2024 14:00:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWCip5JLoLWng+hsPW1YlsV5pCxGLXlLNyZXUPjIz/jfY0CLX9jK8nEbl0pPJdgQNdQGtzbQ== X-Received: by 2002:a05:6214:230b:b0:6c5:3338:45d7 with SMTP id 6a1803df08f44-6c573801fc6mr150920826d6.12.1726693201812; Wed, 18 Sep 2024 14:00:01 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c75e44bf15sm1011446d6.11.2024.09.18.14.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:00:00 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 2/2] c++: CWG 2789 and usings [PR116492] Date: Wed, 18 Sep 2024 16:59:46 -0400 Message-ID: <20240918205946.4082171-2-ppalka@redhat.com> X-Mailer: git-send-email 2.46.1.544.g3fb745257b In-Reply-To: <20240918205946.4082171-1-ppalka@redhat.com> References: <20240918205946.4082171-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? I'm not sure this is worth backporting without the previous CWG 2273 tweak since it'll mean inconsistent behavior between implict vs explicit object members in GCC 14: the call to S<>{}.f() in concepts-memfun4.C would now return 10 (due to the CWG 2273 tiebreaker incorrectly triggering), while the g() and h() calls would be ambiguous (since that tiebreaker doesn't consider object correspondence). Also I'm not 100% sure if I'm interpreting "both are direct members of the same class" correctly here to mean ruling out using'd vs non-using'd members, since https://eel.is/c++draft/namespace.udecl#note-5 says using'd members are "treated as though they were direct members of the derived class"...? -- >8 -- After CWG 2789, the "more constrained" tiebreaker for non-template functions should exclude members that come from different classes via using. This patch implements this missing refinement. In turn we can get rid of four-parameter overload of object_parms_correspond and call the main overload directly since we know correspondence is now only checked for members from the same class. PR c++/116492 DR 2789 gcc/cp/ChangeLog: * call.cc (object_parms_correspond): Remove. (cand_parms_match): Return false for member functions that come from different classes. Adjust call to object_parms_correspond. (joust): Update comment for the non-template "more constrained" case. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-memfun4.C: Expect ambiguity when candidates come from different classes. * g++.dg/cpp2a/concepts-inherit-ctor12.C: New test. --- gcc/cp/call.cc | 54 +++++++------------ .../g++.dg/cpp2a/concepts-inherit-ctor12.C | 16 ++++++ gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C | 24 +++++---- 3 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor12.C diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 87b54291b51..de742da6927 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -12808,27 +12808,6 @@ class_of_implicit_object (z_candidate *cand) return BINFO_TYPE (cand->conversion_path); } -/* True if candidates C1 and C2 have corresponding object parameters per - [basic.scope.scope]. */ - -static bool -object_parms_correspond (z_candidate *c1, tree fn1, z_candidate *c2, tree fn2) -{ - tree context = class_of_implicit_object (c1); - tree ctx2 = class_of_implicit_object (c2); - if (!ctx2) - /* Leave context as is. */; - else if (!context) - context = ctx2; - else if (context != ctx2) - /* This can't happen for normal function calls, since it means finding - functions in multiple bases which would fail with an ambiguous lookup, - but it can occur with reversed operators. */ - return false; - - return object_parms_correspond (fn1, fn2, context); -} - /* Return whether the first parameter of C1 matches the second parameter of C2. */ @@ -12893,16 +12872,19 @@ cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind) 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))) - /* Early escape. */; - - /* CWG2789 is not adequate, it should specify corresponding object - parameters, not same typed object parameters. */ - else if (!object_parms_correspond (c1, fn1, c2, fn2)) - return false; - else + if (DECL_FUNCTION_MEMBER_P (fn1) + && DECL_FUNCTION_MEMBER_P (fn2)) { + tree base1 = DECL_CONTEXT (strip_inheriting_ctors (fn1)); + tree base2 = DECL_CONTEXT (strip_inheriting_ctors (fn2)); + if (base1 != base2) + return false; + + /* CWG2789 is not adequate, it should specify corresponding object + parameters, not same typed object parameters. */ + if (!object_parms_correspond (fn1, fn2, base1)) + return false; + /* We just compared the object parameters, if they don't correspond we already returned false. */ auto skip_parms = [] (tree fn, tree parms) @@ -13269,10 +13251,14 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn, return winner; } - /* Concepts: F1 and F2 are non-template functions with the same - parameter-type-lists, and F1 is more constrained than F2 according to the - partial ordering of constraints described in 13.5.4. */ - + /* F1 and F2 are non-template functions and + - they have the same non-object-parameter-type-lists ([dcl.fct]), and + - if they are member functions, both are direct members of the same + class, and + - if both are non-static member functions, they have the same types for + their object parameters, and + - F1 is more constrained than F2 according to the partial ordering of + constraints described in [temp.constr.order]. */ if (flag_concepts && DECL_P (cand1->fn) && DECL_P (cand2->fn) && !cand1->template_decl && !cand2->template_decl && cand_parms_match (cand1, cand2, pmatch::current)) diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor12.C b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor12.C new file mode 100644 index 00000000000..3e5dbfc37ad --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor12.C @@ -0,0 +1,16 @@ +// PR c++/116492 +// CWG 2789 +// { dg-do compile { target c++20 } } + +template +struct A { + A() requires true = delete; +}; + +struct B : A { + B(); + using A::A; +}; + +B b; // OK, selects the non-inherited constructor over the more constrained + // inherited constructor. diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C index 91e34f1cd7a..62e304b5322 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C @@ -1,5 +1,7 @@ // PR c++/113191 -// { dg-do compile { target c++23 } } +// CWG 2789 +// { dg-do compile { target c++20 } } +// { dg-additional-options "-Wno-error=c++23-extensions" { target c++20_only } } template struct S; @@ -8,6 +10,7 @@ struct B { constexpr int f() const requires true { return 5; } constexpr operator int () const requires true { return 5; } constexpr int g(this S&&) requires true { return 5; } + // { dg-warning "explicit object" "" { target c++20_only } .-1 } constexpr int h() requires true { return 5; } }; @@ -20,12 +23,14 @@ struct S : B<> { constexpr operator int () const { return 10; } constexpr int g() { return 10; } constexpr int h(this S&&) { return 10; } + // { dg-warning "explicit object" "" { target c++20_only } .-1 } }; -// implicit object parms match, B::f is more constrained -static_assert(S<>{}.f() == 5); -static_assert(S<>{}.g() == 5); -static_assert(S<>{}.h() == 5); +// ambiguous, constraints aren't considered since the candidates +// are defined from different classes +static_assert(S<>{}.f() == 5); // { dg-error "ambiguous" } +static_assert(S<>{}.g() == 5); // { dg-error "ambiguous" } +static_assert(S<>{}.h() == 5); // { dg-error "ambiguous" } template struct C { @@ -36,9 +41,8 @@ struct C { template struct S2: B<>, C<> { }; -// implicit object parms for conversion functions are all considered to be from -// the class of the object argument -static_assert(S2<>{} == 5); +// ambiguous as above +static_assert(S2<>{} == 5); // { dg-error "ambiguous" } // ambiguous lookup, so we never actually compare the candidates // if we did, implicit object parms don't match due to different classes @@ -51,7 +55,6 @@ struct S3 : B<> { constexpr int f() volatile { return 10; } }; -// implicit object parms don't match due to different cv-quals static_assert(S3<>{}.f() == 5); // { dg-error "ambiguous" } template @@ -60,8 +63,7 @@ struct S4 : B<> { constexpr int f() const & { return 10; } }; -// no ref-qual matches any ref-qual -static_assert(S4<>{}.f() == 5); +static_assert(S4<>{}.f() == 5); // { dg-error "ambiguous" } template struct C2 {