From patchwork Fri Nov 8 00:32:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1191540 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512773-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="m0AOkhQ/"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="NwWDQQ2r"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 478Lp149M7z9sPT for ; Fri, 8 Nov 2019 11:32:39 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=X16eap1BlmLps3Y9R9RNeWwg0pGcTf4lwEeJUQO5I19RZ7EMGsZul P/JGMEN4WbksSj8GfczhEPGJRSe5eHgTDig14YSUzcJVQzybtcH++IcJ52evv0Jy EgU5CR8V7GFuNfcL4ipo1NIQsUd2kqrqXx8F1xuY3XFjZmzhg0gI24= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=tWr+HnMEXw0f8vgVRWxldmIxW1A=; b=m0AOkhQ/KiKqiyHygkvA gcEN+4r00mhK/eHdRu01GEm8QBbBwDN82SM/EbYh0m12Ud32uHe28SE1uH+nhm14 C5vwEbB3iypabvGFbylzDRZoh8lEA7Pa6KCqadGOcK9IdiSjzvEeMvvhlNlyvymJ 2PBJTLzx4eFhI2X9A4XjT/g= Received: (qmail 63484 invoked by alias); 8 Nov 2019 00:32:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 63467 invoked by uid 89); 8 Nov 2019 00:32:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_SHORT autolearn=unavailable version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Nov 2019 00:32:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573173141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=/g3ozuRWa9ER8kq2sJ16F0enCDYwp+He8ivkVNAUag4=; b=NwWDQQ2r8l1ekHJJe7IUh3EN6pNOSCcmY7dMooK9ZUIW/8zzU8fck8+f1s4PeY/eKTNSzm VX8gM/NISudKOa5oNiWZ4WmS71dpSBy47l/MverZPCkvh8pCQvVTI3xhxhg/E/LTGboix6 qSub4AAkaPYmIFp9OHqssjbpeySPCD0= 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-171-JWFw9QJtNGOJwqoZqQxXQg-1; Thu, 07 Nov 2019 19:32:18 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 960BA477; Fri, 8 Nov 2019 00:32:17 +0000 (UTC) Received: from localhost (unknown [10.33.36.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F33E5C219; Fri, 8 Nov 2019 00:32:16 +0000 (UTC) Date: Fri, 8 Nov 2019 00:32:15 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: define std::common_comparison_category for C++20 Message-ID: <20191108003215.GA31051@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.12.1 (2019-06-15) X-Mimecast-Spam-Score: 0 Content-Disposition: inline * libsupc++/compare (common_comparison_category) (common_comparison_category_t): Define for C++20. * testsuite/18_support/comparisons/common/1.cc: New test. Tested powerpc64le-linux, committed to trunk. commit cb48e7e6d0bbed9eadc34b4318511f3e05ec1b64 Author: Jonathan Wakely Date: Thu Nov 7 21:33:36 2019 +0000 libstdc++: define std::common_comparison_category for C++20 * libsupc++/compare (common_comparison_category) (common_comparison_category_t): Define for C++20. * testsuite/18_support/comparisons/common/1.cc: New test. diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index 84cc3f5c85f..94728e29de8 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -385,18 +385,81 @@ namespace std is_gteq(partial_ordering __cmp) noexcept { return __cmp >= 0; } +#if __cpp_lib_concepts + namespace __detail + { + template + inline constexpr unsigned __cmp_cat_id = 1; + template<> + inline constexpr unsigned __cmp_cat_id = 2; + template<> + inline constexpr unsigned __cmp_cat_id = 4; + template<> + inline constexpr unsigned __cmp_cat_id = 8; + + template + constexpr unsigned __cmp_cat_ids() + { return (__cmp_cat_id<_Ts> | ...); } + + template + struct __common_cmp_cat; + + // If any Ti is not a comparison category type, U is void. + template + requires ((_Bits & 1) == 1) + struct __common_cmp_cat<_Bits> { using type = void; }; + + // Otherwise, if at least one Ti is std::partial_ordering, + // U is std::partial_ordering. + template + requires ((_Bits & 0b1001) == 0b1000) + struct __common_cmp_cat<_Bits> { using type = partial_ordering; }; + + // Otherwise, if at least one Ti is std::weak_ordering, + // U is std::weak_ordering. + template + requires ((_Bits & 0b1101) == 0b0100) + struct __common_cmp_cat<_Bits> { using type = weak_ordering; }; + + // Otherwise, U is std::strong_ordering. + template<> + struct __common_cmp_cat<0b0010> { using type = strong_ordering; }; + } // namespace __detail + // [cmp.common], common comparison category type template struct common_comparison_category { - // using type = TODO + using type + = __detail::__common_cmp_cat<__detail::__cmp_cat_ids<_Ts...>()>::type; }; + // Partial specializations for one and zero argument cases. + + template + struct common_comparison_category<_Tp> + { using type = void; }; + + template<> + struct common_comparison_category + { using type = partial_ordering; }; + + template<> + struct common_comparison_category + { using type = weak_ordering; }; + + template<> + struct common_comparison_category + { using type = strong_ordering; }; + + template<> + struct common_comparison_category<> + { using type = strong_ordering; }; + template using common_comparison_category_t = typename common_comparison_category<_Ts...>::type; -#if __cpp_lib_concepts namespace __detail { template @@ -493,22 +556,22 @@ 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 - { - if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>) - { - auto __pt = static_cast(__t); - auto __pu = static_cast(__u); - if (__builtin_is_constant_evaluated()) - return __pt <=> __pu; - auto __it = reinterpret_cast<__UINTPTR_TYPE__>(__pt); - auto __iu = reinterpret_cast<__UINTPTR_TYPE__>(__pu); - return __it <=> __iu; - } - else - return static_cast<_Tp&&>(__t) <=> static_cast<_Up&&>(__u); - } + constexpr auto + operator()(_Tp&& __t, _Up&& __u) const noexcept + { + if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>) + { + auto __pt = static_cast(__t); + auto __pu = static_cast(__u); + if (__builtin_is_constant_evaluated()) + return __pt <=> __pu; + auto __it = reinterpret_cast<__UINTPTR_TYPE__>(__pt); + auto __iu = reinterpret_cast<__UINTPTR_TYPE__>(__pu); + return __it <=> __iu; + } + else + return static_cast<_Tp&&>(__t) <=> static_cast<_Up&&>(__u); + } using is_transparent = void; }; diff --git a/libstdc++-v3/testsuite/18_support/comparisons/common/1.cc b/libstdc++-v3/testsuite/18_support/comparisons/common/1.cc new file mode 100644 index 00000000000..015a8acae97 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/comparisons/common/1.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2019 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 + +template +constexpr bool check() +{ + return std::same_as>; +} + +using std::partial_ordering; +using std::weak_ordering; +using std::strong_ordering; + +static_assert(check()); +static_assert(check()); +static_assert(check()); +static_assert(check()); +static_assert(check()); +static_assert(check()); +static_assert(check()); + +using PO = std::partial_ordering; +using WO = std::weak_ordering; +using SO = std::strong_ordering; + +static_assert(check()); +static_assert(check()); +static_assert(check()); +static_assert(check());