From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113434 invoked by alias); 20 Feb 2020 11:32:01 -0000 Mailing-List: contact libstdc++-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libstdc++-owner@gcc.gnu.org Received: (qmail 113396 invoked by uid 89); 20 Feb 2020 11:31:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Feb 2020 11:31:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582198315; 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=7WffjBerlIhgrIy0sP4w9iGfFjs+BRowA4NuTpFfEwc=; b=CvTX9QkKNz3hr6adt8xCwh+wcBe7ghxHRZFmjSvCkgcIrAJ5oXox8OZ5i5CECn7HknViwU IR5a69WGusBNDkHCybx+H/kGIRPRikXVSF2iR+bL4ibtQg7nhNomKy+sQ3c2Ek/TiqTWCN pv0p0cUDjg4gkWJX0X3G1KsllFKApcs= 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-50-6lntx-BCMvmEub4QDs6fvQ-1; Thu, 20 Feb 2020 06:31:52 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4E5D8017DF; Thu, 20 Feb 2020 11:31:51 +0000 (UTC) Received: from localhost (unknown [10.33.36.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 604285DA82; Thu, 20 Feb 2020 11:31:51 +0000 (UTC) Date: Thu, 20 Feb 2020 11:32:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Add <=> to thread::id Message-ID: <20200220113150.GA1843957@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="ZPt4rx8FFjLCG7dd" Content-Disposition: inline X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00133.txt.bz2 --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 313 * include/std/thread (thread::id::operator<=3D>): Define for C++20. * testsuite/30_threads/thread/id/70294.cc: Do not take addresses of functions in namespace std. * testsuite/30_threads/thread/id/operators_c++20.cc: New test. This is a small part of P1614R2. Tested powerpc64le-linux, committed to master. --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-Transfer-Encoding: quoted-printable Content-length: 7220 commit c7b591f3868f778ce89b14cbfb81d8e96d0daad2 Author: Jonathan Wakely Date: Fri Feb 7 20:28:06 2020 +0000 libstdc++: Add <=3D> to thread::id =20=20=20=20 * include/std/thread (thread::id::operator<=3D>): Define for C+= +20. * testsuite/30_threads/thread/id/70294.cc: Do not take addresse= s of functions in namespace std. * testsuite/30_threads/thread/id/operators_c++20.cc: New test. diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thr= ead index b533bca578f..1f9c13ff7d1 100644 --- a/libstdc++-v3/include/std/thread +++ b/libstdc++-v3/include/std/thread @@ -45,7 +45,8 @@ #include // std::tuple =20 #if __cplusplus > 201703L -# include // std::stop_source, std::stop_token, std::nostopst= ate +# include // std::strong_ordering +# include // std::stop_source, std::stop_token, std::nostopst= ate #endif =20 #ifdef _GLIBCXX_USE_NANOSLEEP @@ -96,17 +97,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION =20 private: friend class thread; - friend class hash; + friend class hash; =20 friend bool - operator=3D=3D(thread::id __x, thread::id __y) noexcept; + operator=3D=3D(id __x, id __y) noexcept; =20 +#if __cpp_lib_three_way_comparison + friend strong_ordering + operator<=3D>(id __x, id __y) noexcept; +#else friend bool - operator<(thread::id __x, thread::id __y) noexcept; + operator<(id __x, id __y) noexcept; +#endif =20 template friend basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id); + operator<<(basic_ostream<_CharT, _Traits>& __out, id __id); }; =20 private: @@ -180,7 +186,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void detach(); =20 - thread::id + id get_id() const noexcept { return _M_id; } =20 @@ -296,6 +302,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __x._M_thread =3D=3D __y._M_thread; } =20 +#if __cpp_lib_three_way_comparison + inline strong_ordering + operator<=3D>(thread::id __x, thread::id __y) noexcept + { return __x._M_thread <=3D> __y._M_thread; } +#else inline bool operator!=3D(thread::id __x, thread::id __y) noexcept { return !(__x =3D=3D __y); } @@ -319,6 +330,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline bool operator>=3D(thread::id __x, thread::id __y) noexcept { return !(__x < __y); } +#endif // __cpp_lib_three_way_comparison =20 // DR 889. /// std::hash specialization for thread::id. @@ -424,8 +436,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class jthread { public: - using id =3D std::thread::id; - using native_handle_type =3D std::thread::native_handle_type; + using id =3D thread::id; + using native_handle_type =3D thread::native_handle_type; =20 jthread() noexcept : _M_stop_source{nostopstate} @@ -498,7 +510,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION [[nodiscard]] static unsigned hardware_concurrency() noexcept { - return std::thread::hardware_concurrency(); + return thread::hardware_concurrency(); } =20 [[nodiscard]] stop_source @@ -544,7 +556,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } =20 stop_source _M_stop_source; - std::thread _M_thread; + thread _M_thread; }; #endif // __cpp_lib_jthread _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/30_threads/thread/id/70294.cc b/libstdc= ++-v3/testsuite/30_threads/thread/id/70294.cc index ac3b58afa75..d9c61f74351 100644 --- a/libstdc++-v3/testsuite/30_threads/thread/id/70294.cc +++ b/libstdc++-v3/testsuite/30_threads/thread/id/70294.cc @@ -19,5 +19,14 @@ =20 #include =20 -bool (*lt)(std::thread::id, std::thread::id) =3D &std::operator<; -bool (*eq)(std::thread::id, std::thread::id) =3D &std::operator=3D=3D; +struct T +{ + operator std::thread::id() const; +} const t; + +using namespace std; + +// std::thread::id comparison operators are not hidden friends, +// so should be candidates for these expressions: +bool lt =3D t < t; +bool eq =3D t =3D=3D t; diff --git a/libstdc++-v3/testsuite/30_threads/thread/id/operators.cc b/lib= stdc++-v3/testsuite/30_threads/thread/id/operators.cc index fb6440bfc3d..3d84afafd15 100644 --- a/libstdc++-v3/testsuite/30_threads/thread/id/operators.cc +++ b/libstdc++-v3/testsuite/30_threads/thread/id/operators.cc @@ -20,16 +20,26 @@ =20 #include =20 +template + struct check_type + : std::false_type + { }; + +template + struct check_type + : std::true_type + { }; + void test01() { // thread::id operators std::thread::id id1; std::thread::id id2; =20 - id1 =3D=3D id2; - id1 !=3D id2; - id1 < id2; - id1 > id2; - id1 >=3D id2; - id1 <=3D id2; + static_assert( check_type{} ); + static_assert( check_type{} ); + static_assert( check_type{} ); + static_assert( check_type id2)>{} ); + static_assert( check_type=3D id2)>{} ); + static_assert( check_type{} ); } diff --git a/libstdc++-v3/testsuite/30_threads/thread/id/operators_c++20.cc= b/libstdc++-v3/testsuite/30_threads/thread/id/operators_c++20.cc new file mode 100644 index 00000000000..6094b0e1501 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/id/operators_c++20.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=3Dgnu++2a" } +// { dg-do compile { target c++2a } } +// { dg-require-gthreads "" } + +// 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 +// . + +#include + +template + struct check_type + : std::false_type + { }; + +template + struct check_type + : std::true_type + { }; + +void test01() +{ + // thread::id operators + std::thread::id id1; + std::thread::id id2; + + static_assert( check_type{} ); + static_assert( check_type{} ); + static_assert( check_type{} ); + static_assert( check_type id2)>{} ); + static_assert( check_type=3D id2)>{} ); + static_assert( check_type{} ); + + static_assert( check_type id2)>= {} ); +} --ZPt4rx8FFjLCG7dd--