From patchwork Tue Apr 14 22:52:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1270756 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=BMycUUVI; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49213R0xD2z9sSd for ; Wed, 15 Apr 2020 08:52:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE2BB385DC17; Tue, 14 Apr 2020 22:52:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE2BB385DC17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586904759; bh=w492kGfs5DScavUlvWKeQfKzlmIcxmNRWHV01T+dl8U=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BMycUUVIx0XuCrI2SdmXkvklUpPjx38+Qsw8n+973HhBrnhE9OuJJ8Q7kPnTKrv7F vUGXK6RVErMiIpRczlkSJZgZLF5uIZotSRRBeEFln8yNdWFV4vPh7MrGmdxTwqoFBe COsMNeyZNDkWGHYbTVqE5/ZdSceqruAnDx8uJGhk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 29482385DC0B for ; Tue, 14 Apr 2020 22:52:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 29482385DC0B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-ruReUyklPE-OGiGen9oZXQ-1; Tue, 14 Apr 2020 18:52:33 -0400 X-MC-Unique: ruReUyklPE-OGiGen9oZXQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22389107ACC9; Tue, 14 Apr 2020 22:52:32 +0000 (UTC) Received: from localhost (unknown [10.33.36.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C9A76EF91; Tue, 14 Apr 2020 22:52:31 +0000 (UTC) Date: Tue, 14 Apr 2020 23:52:30 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix constraints on std::compare_three_way Message-ID: <20200414225230.GA1623527@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-29.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" My "simplification" of std::compare_three_way's constraints in commit f214ffb336d582a66149068a2a96b7fcf395b5de was incorrect, because std::three_way_comparable_with imposes additional restrictions beyond the <=> expression being valid. * libsupc++/compare (compare_three_way): Fix constraint so that BUILTIN-PTR-THREE-WAY does not require three_way_comparable_with. * testsuite/18_support/comparisons/object/builtin-ptr-three-way.cc: New test. Tested powerpc64l-linux, committed to master. commit e1e9e8d7aa7bf1b0d3de34345b6c649e07da7a1e Author: Jonathan Wakely Date: Tue Apr 14 21:58:03 2020 +0100 libstdc++: Fix constraints on std::compare_three_way My "simplification" of std::compare_three_way's constraints in commit f214ffb336d582a66149068a2a96b7fcf395b5de was incorrect, because std::three_way_comparable_with imposes additional restrictions beyond the <=> expression being valid. * libsupc++/compare (compare_three_way): Fix constraint so that BUILTIN-PTR-THREE-WAY does not require three_way_comparable_with. * testsuite/18_support/comparisons/object/builtin-ptr-three-way.cc: New test. diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index 5f1df19e445..e5fb322ed9e 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -481,13 +481,14 @@ namespace std // BUILTIN-PTR-THREE-WAY(T, U) template concept __3way_builtin_ptr_cmp - = three_way_comparable_with<_Tp, _Up> + = requires(_Tp&& __t, _Up&& __u) + { static_cast<_Tp&&>(__t) <=> static_cast<_Up&&>(__u); } && convertible_to<_Tp, const volatile void*> && convertible_to<_Up, const volatile void*> && ! requires(_Tp&& __t, _Up&& __u) - { operator<=>(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); } + { operator<=>(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); } && ! requires(_Tp&& __t, _Up&& __u) - { static_cast<_Tp&&>(__t).operator<=>(static_cast<_Up&&>(__u)); }; + { static_cast<_Tp&&>(__t).operator<=>(static_cast<_Up&&>(__u)); }; } // namespace __detail // [cmp.object], typename compare_three_way @@ -495,6 +496,7 @@ namespace std { template requires three_way_comparable_with<_Tp, _Up> + || __detail::__3way_builtin_ptr_cmp<_Tp, _Up> constexpr auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::declval<_Tp>() <=> std::declval<_Up>())) diff --git a/libstdc++-v3/testsuite/18_support/comparisons/object/builtin-ptr-three-way.cc b/libstdc++-v3/testsuite/18_support/comparisons/object/builtin-ptr-three-way.cc new file mode 100644 index 00000000000..38b3c6e3211 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/comparisons/object/builtin-ptr-three-way.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +void +test01() +{ + struct X + { + operator int() const { return 0; } + operator long*() const { return nullptr; } + } x; + + // Not three-way-comparable because of ambiguous conversion to int or long*: + static_assert( ! std::three_way_comparable ); + + // And therefore X is not three-way-comparable-with anything else + // (because std::three_way_comparable_with requires that both + // three_way_comparable and three_way_comparable are true). + static_assert( ! std::three_way_comparable_with ); + + long l; + // But <=> is valid and resolves to a builtin operator comparing pointers: + auto c = &l <=> x; + // So std::compare_three_way should be usable: + auto c2 = std::compare_three_way()(&l, x); +}