From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E703B3858D3C for ; Mon, 7 Nov 2022 22:57:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E703B3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667861832; 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: in-reply-to:in-reply-to:references:references; bh=fE7kcDA2aC00aAa+U9zuF+FYShsZBHe8T+ZzsW1Zv78=; b=RailYQexkX+L29CoLnCZGtXjxoJFCHybXaoHtGxhgkALfArufWN9oaZZUD0wgwMZeTRpPl 5tARfeAl9XfGvWmdwkGlARrGZl/yUQ+ZwqejTYvnZHuEOLVIY+MGNphaKSYmuKWChJQV/0 zidPWSPd/378bGLE5/9mLg4GRKbDRfc= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-378-pxNUREUaPTebA84Fsbnd4g-1; Mon, 07 Nov 2022 17:57:11 -0500 X-MC-Unique: pxNUREUaPTebA84Fsbnd4g-1 Received: by mail-ed1-f72.google.com with SMTP id s15-20020a056402520f00b0046321fff42dso9216453edd.0 for ; Mon, 07 Nov 2022 14:57:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fE7kcDA2aC00aAa+U9zuF+FYShsZBHe8T+ZzsW1Zv78=; b=xC61zM7+SQpB7/j+3F5HDVfH5SxGM9hnSCXLTLNqvhBZPyw23KdOdQrkMJJugfJvgE enlQobJBDBc+Cr8Zcm88gx2n8P6KaYVKQkuN9u/BDZAioHAtBZOV7iNkgr9OsERDmgaf WB4goDCPt5mRQAS+8dFEgtJJTl9dSsAqngmPnyQPWvQHI1g7oeqgOVZULDNoPjTqE258 Obra3hTI5MCLsAzjlkQTZUyJW4foEXFhZUBLjGInSqVQZEgCZUvNZtMF6Z02ITXlORXU Zg5SjAcw5LtJkmN6L98d0CtHijn5WI+wl3AemTfraawpQnoR9vwvm4euA606HPRCCGCk 5oCg== X-Gm-Message-State: ACrzQf0rXV7KjNZwzdTIBjblGWx7pxawQ72MgBqX3Ix885bw9eJXhN8F qJ8smVKEUVPhG3x6KzMolhtvS0Lz1xeTFFjGvD2eyHZ8mGKAemgtH6psgq488udELVGd40hAx5g YztUdALz9nyD0dTTXLumApeKR+vwFEiyC+A== X-Received: by 2002:a17:906:cc58:b0:7a9:6b4e:79e4 with SMTP id mm24-20020a170906cc5800b007a96b4e79e4mr48409527ejb.57.1667861830479; Mon, 07 Nov 2022 14:57:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM4zaBORZAVmHwDieJa1bXGMHWsxU827T8cS1zIV5hop6zGyjwX5ZXCl3iO5WdfQ1EwEh2BgUbOCEKfwvpf0kZE= X-Received: by 2002:a17:906:cc58:b0:7a9:6b4e:79e4 with SMTP id mm24-20020a170906cc5800b007a96b4e79e4mr48409513ejb.57.1667861830252; Mon, 07 Nov 2022 14:57:10 -0800 (PST) MIME-Version: 1.0 References: <20221107205752.2735464-1-jason@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Mon, 7 Nov 2022 22:56:59 +0000 Message-ID: Subject: Re: [PATCH RFC(libstdc++)] c++: implement P2468R2, the equality operator you are looking for To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, Jakub Jelinek X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 List-Id: On Mon, 7 Nov 2022 at 22:49, Jason Merrill wrote: > > On 11/7/22 12:04, Jonathan Wakely wrote: > > On Mon, 7 Nov 2022 at 21:56, Jonathan Wakely wrote: > >> > >> On Mon, 7 Nov 2022 at 20:58, Jason Merrill wrote: > >>> > >>> Tested x86_64-pc-linux-gnu. Jonathan, what do you want to do about the library > >>> test failure? > >>> > >>> -- >8 -- > >>> > >>> This paper is resolving the problem of well-formed C++17 code becoming > >>> ambiguous in C++20 due to asymmetrical operator== being compared with itself > >>> in reverse. I had previously implemented a tiebreaker such that if the two > >>> candidates were functions with the same parameter types, we would prefer the > >>> non-reversed candidate. But the committee went with a different approach: > >>> if there's an operator!= with the same parameter types as the operator==, > >>> don't consider the reversed form of the ==. > >>> > >>> So this patch implements that, and changes my old tiebreaker to give a > >>> pedwarn if it is used. I also noticed that we were giving duplicate errors > >>> for some testcases, and fixed the tourney logic to avoid that. > >>> > >>> As a result, a lot of tests of the form > >>> > >>> struct A { bool operator==(const A&); }; > >>> > >>> need to be fixed to add a const function-cv-qualifier, e.g. > >>> > >>> struct A { bool operator==(const A&) const; }; > >>> > >>> The committee thought such code ought to be fixed, so breaking it was fine. > >>> > >>> 18_support/comparisons/algorithms/fallback.cc also breaks with this patch, > >>> because of the similarly asymmetrical > >>> > >>> bool operator==(const S&, S&) { return true; } > >>> > >>> I assume this was written this way deliberately, so I'm not sure what to do > >>> about it. > >> > >> Yes, that was deliberate. The compare_strong_order_fallback function > >> has these constraints: > >> > >> template _Up> > >> requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up> > >> constexpr strong_ordering > >> operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const > >> > >> And similarly for the other fallbacks. So I wanted to check that two > >> types that decay to the same type (like S and const S) can be compared > >> with == and <, and therefore can be used with this function. > >> > >> But if such asymmetry is no longer allowed, maybe the library function > >> is no longer usable with pathological cases like the test, and so the > >> test should be changed. We can't just replace the decayed_same_as > >> constraint with same_as because the std::strong_order customization > >> point still supports similar types, but we could do: > >> > >> --- a/libstdc++-v3/libsupc++/compare > >> +++ b/libstdc++-v3/libsupc++/compare > >> @@ -1057,11 +1057,11 @@ namespace std _GLIBCXX_VISIBILITY(default) > >> }; > >> > >> template > >> - concept __op_eq_lt = requires(_Tp&& __t, _Up&& __u) > >> + concept __op_eq_lt = same_as<_Tp, _Up> && requires(_Tp&& __t) > >> { > >> - { static_cast<_Tp&&>(__t) == static_cast<_Up&&>(__u) } > >> + { static_cast<_Tp&&>(__t) == static_cast<_Tp&&>(__t) } > >> -> convertible_to; > >> - { static_cast<_Tp&&>(__t) < static_cast<_Up&&>(__u) } > >> + { static_cast<_Tp&&>(__t) < static_cast<_Tp&&>(__t) } > >> -> convertible_to; > >> }; > > > > No wait, that's nonsense. We can still try to compare similar types, > > it's just that they won't be comparable unless their comparison ops > > have two parameters of the same type. > > Basically, though in this case the problem is that the arguments are the > same type and the parameters are different. Ah, so the operator== isn't actually rejected (despite being pathologically dumb) it's just that some uses of it result in ambiguities. > >> And then adjust the test accordingly. If those fallbacks can no longer > >> support mixed types, does the resolution of > >> https://cplusplus.github.io/LWG/issue3465 even make sense now? If E > >> and F must be the same type now, then E < F already implies F < E. I > >> think we need some library changes to sync with P2468R2. > > > > I think this bit was right though. E and F might be different types, > > but E < F implies F < E. Is that right? > > The P2468 changes only affect ==/!=, not <, so LWG3465 should be unaffected. Gotcha. > I think the only problem is the test itself: the asserts need to > be inverted because S and S cannot be compared for equality with the > asymmetrical op== due to the normal candidate being better for arg 2 and > the reversed candidate being better for arg 1. The asserts > are fine because the arguments match the asymmetry, so the normal > candidate is better for both args. Gotcha. > So, the below fixes the test, does > it make sense to you? Yep, looks good. Thanks.