From patchwork Fri Sep 20 18:48:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1988019 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B9U5LAhQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X9Lz51YW8z1y2J for ; Sat, 21 Sep 2024 04:49:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8588E385842A for ; Fri, 20 Sep 2024 18:49:33 +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 A34843858D29 for ; Fri, 20 Sep 2024 18:49:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A34843858D29 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 A34843858D29 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=1726858154; cv=none; b=GO0Tb74aI9FuwfHnR2aRt9ovrpX8Y589wyD9u1ke+rXw62FWnJRsUO9kLsGFOA7KLXZponsVYwcTj8667Eixk3fHfMuupfNzHXCnvou4rS96sfhxw6NzfE/Ef5XwK//ZIAqnzgX2zKuBWErgi+hm7LjI4Pti/2vQZT5rOsCI/kM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726858154; c=relaxed/simple; bh=Os7TH0qQBGN+dclXPXPCSDqVE+BQTqBcgKzc4ygaJrs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XmBGSGj0Ro2rAcvbI/DdEWVqz/pVFxRuiDwD/QGeVLqIUaopgVk1/QG6J2cVNztiODUuykeGxqvzqnbYPg2h8RORg7dsT7lQ0zNZu69LWtGbkYgiGKqRv0mOP7L+8Du0yvqmmgC9e13ORXOSjBOW9WPNxTXbLLERFBdJTRo22os= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726858143; 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=SeVrKs+d34cAvg1iNIPEMXXOHuyh5J4M9OiV929rf90=; b=B9U5LAhQIv3cM6bjPxhu3rV+tFeKgsN/k1kbn8Lp4dZkfS1z617yRtdEF6ELPC8BCwomfW Md/muvbT/jvDFecBb+hqkkVoKImC2o/Sgbgs8mL4ep2RgZ7esYRqFDwo3VxX0GL+U/3CVs Tp2H671bF8i0A8X9IGlcjCifSMPGwMo= 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-h4Z__VmSNayPGHaHcxNOPw-1; Fri, 20 Sep 2024 14:49:01 -0400 X-MC-Unique: h4Z__VmSNayPGHaHcxNOPw-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-459a5d016f9so3227761cf.2 for ; Fri, 20 Sep 2024 11:49:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726858140; x=1727462940; 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=SeVrKs+d34cAvg1iNIPEMXXOHuyh5J4M9OiV929rf90=; b=J0TexMw6EPnD4V9hGtjsTboScBWHWtZGR7LN3LqCuCdIqgDabHAbzFXsqlLlh58nju NB47Hk7ICCA5RQFMIzwe8dTK30yM1/p8e42HZQdvZyZgZq8OjNFP3Eloc0/MM7jRNyRn a/SJlh6QCsLO62F0UUpVqL930TbJbwc4XNJOtnPRoJfyVGV3C0pd3tPaYqGD2haSuImh NCC8qkWUvySBLhFrOzjbL4kS2dd1tWljkChS+84QErvrGJqPBSR0e40VVW/JvbbRBkXH VBUT7iWPFYKizzYzgyD/arFtYJhGLbQ4V5ZeWlMswyKd1VQ9s/FZBej5kicq7r54NRAH 9BrQ== X-Gm-Message-State: AOJu0Yx7lYqmjU4agyImi0VebxBkn/fMWUS3dL7rIbnXdnQIL5+iCVlE ZzK6y2RANXmAr19uxcZ+XywsZ//rnwjgkhPbE7W72aHseveiXe/2hx7mDT587HKIQdXGth5otEn Atk1YQ0hY7b/hIexIdYM2p/sQS3QWf/Mhnhvltx5GZ+sSM7ijhzTCFclqj0nBRRQ09gbQhVZ4Q6 yt6OvRJLSW/wmKtZkkmdxf5X7WmtIbnleNaT96 X-Received: by 2002:ac8:5742:0:b0:458:59b4:4609 with SMTP id d75a77b69052e-45b2050168cmr28799881cf.8.1726858140380; Fri, 20 Sep 2024 11:49:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHh8lHe8WYJogZ8nnvNh+iNtcK95vb5XUkNlCtZVxMyB/8m+lAti47OFPyQx0rcZNykE4loeQ== X-Received: by 2002:ac8:5742:0:b0:458:59b4:4609 with SMTP id d75a77b69052e-45b2050168cmr28799651cf.8.1726858139973; Fri, 20 Sep 2024 11:48:59 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b178f2d71sm21030031cf.76.2024.09.20.11.48.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 11:48:59 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: CWG 2789 and reversed operator candidates Date: Fri, 20 Sep 2024 14:48:56 -0400 Message-ID: <20240920184857.720642-1-ppalka@redhat.com> X-Mailer: git-send-email 2.46.1.565.g6531f31ef3 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- As a follow-up to r15-3741-gee3efe06c9c49c, which was only concerned with usings, it seems we should also compare contexts of a reversed vs non-reversed (member) candidate during operator overload resolution. DR 2789 gcc/cp/ChangeLog: * call.cc (cand_parms_match): Check for matching class contexts even in the reversed case. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-memfun4.C: Adjust expected result involving reversed candidate. --- gcc/cp/call.cc | 11 +++++++---- gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index f2ce50857ec..70783baac24 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -12865,10 +12865,6 @@ cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind) } } - else if (reversed) - return (reversed_match (c1, c2) - && reversed_match (c2, c1)); - tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1)); tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2)); @@ -12880,6 +12876,10 @@ cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind) if (base1 != base2) return false; + if (reversed) + return (reversed_match (c1, c2) + && reversed_match (c2, c1)); + /* Use object_parms_correspond to simplify comparing iobj/xobj/static member functions. */ if (!object_parms_correspond (fn1, fn2, base1)) @@ -12897,6 +12897,9 @@ cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind) parms1 = skip_parms (fn1, parms1); parms2 = skip_parms (fn2, parms2); } + else if (reversed) + return (reversed_match (c1, c2) + && reversed_match (c2, c1)); return compparms (parms1, parms2); } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C index cf7f13c007d..d849e9129a3 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-memfun4.C @@ -91,7 +91,7 @@ namespace N1 { A<> a; B<> b; - // when comparing the A op== to the reversed B op==, we compare them in - // reverse order, so they match, and we choose the more constrained. - static_assert (a == b); + // A op== and B op== are defined in different classes so constraints + // aren't considered, and the tie is broken via reversedness. + static_assert (!(a == b)); }