* include/std/thread (thread::id::operator<=>): 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.
+2020-02-20 Jonathan Wakely <jwakely@redhat.com>
+
+ * include/std/thread (thread::id::operator<=>): 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.
+
2020-02-19 Patrick Palka <ppalka@redhat.com>
* testsuite/std/ranges/adaptors/split.cc (test03): Don't include the
#include <tuple> // std::tuple
#if __cplusplus > 201703L
-# include <stop_token> // std::stop_source, std::stop_token, std::nostopstate
+# include <compare> // std::strong_ordering
+# include <stop_token> // std::stop_source, std::stop_token, std::nostopstate
#endif
#ifdef _GLIBCXX_USE_NANOSLEEP
private:
friend class thread;
- friend class hash<thread::id>;
+ friend class hash<id>;
friend bool
- operator==(thread::id __x, thread::id __y) noexcept;
+ operator==(id __x, id __y) noexcept;
+#if __cpp_lib_three_way_comparison
+ friend strong_ordering
+ operator<=>(id __x, id __y) noexcept;
+#else
friend bool
- operator<(thread::id __x, thread::id __y) noexcept;
+ operator<(id __x, id __y) noexcept;
+#endif
template<class _CharT, class _Traits>
friend basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id);
+ operator<<(basic_ostream<_CharT, _Traits>& __out, id __id);
};
private:
void
detach();
- thread::id
+ id
get_id() const noexcept
{ return _M_id; }
return __x._M_thread == __y._M_thread;
}
+#if __cpp_lib_three_way_comparison
+ inline strong_ordering
+ operator<=>(thread::id __x, thread::id __y) noexcept
+ { return __x._M_thread <=> __y._M_thread; }
+#else
inline bool
operator!=(thread::id __x, thread::id __y) noexcept
{ return !(__x == __y); }
inline bool
operator>=(thread::id __x, thread::id __y) noexcept
{ return !(__x < __y); }
+#endif // __cpp_lib_three_way_comparison
// DR 889.
/// std::hash specialization for thread::id.
class jthread
{
public:
- using id = std::thread::id;
- using native_handle_type = std::thread::native_handle_type;
+ using id = thread::id;
+ using native_handle_type = thread::native_handle_type;
jthread() noexcept
: _M_stop_source{nostopstate}
[[nodiscard]] static unsigned
hardware_concurrency() noexcept
{
- return std::thread::hardware_concurrency();
+ return thread::hardware_concurrency();
}
[[nodiscard]] stop_source
}
stop_source _M_stop_source;
- std::thread _M_thread;
+ thread _M_thread;
};
#endif // __cpp_lib_jthread
_GLIBCXX_END_NAMESPACE_VERSION
#include <thread>
-bool (*lt)(std::thread::id, std::thread::id) = &std::operator<;
-bool (*eq)(std::thread::id, std::thread::id) = &std::operator==;
+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 = t < t;
+bool eq = t == t;
#include <thread>
+template<typename Expected, typename T>
+ struct check_type
+ : std::false_type
+ { };
+
+template<typename Expected>
+ struct check_type<Expected, Expected>
+ : std::true_type
+ { };
+
void test01()
{
// thread::id operators
std::thread::id id1;
std::thread::id id2;
- id1 == id2;
- id1 != id2;
- id1 < id2;
- id1 > id2;
- id1 >= id2;
- id1 <= id2;
+ static_assert( check_type<bool, decltype(id1 == id2)>{} );
+ static_assert( check_type<bool, decltype(id1 != id2)>{} );
+ static_assert( check_type<bool, decltype(id1 < id2)>{} );
+ static_assert( check_type<bool, decltype(id1 > id2)>{} );
+ static_assert( check_type<bool, decltype(id1 >= id2)>{} );
+ static_assert( check_type<bool, decltype(id1 <= id2)>{} );
}
--- /dev/null
+// { dg-options "-std=gnu++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
+// <http://www.gnu.org/licenses/>.
+
+#include <thread>
+
+template<typename Expected, typename T>
+ struct check_type
+ : std::false_type
+ { };
+
+template<typename Expected>
+ struct check_type<Expected, Expected>
+ : std::true_type
+ { };
+
+void test01()
+{
+ // thread::id operators
+ std::thread::id id1;
+ std::thread::id id2;
+
+ static_assert( check_type<bool, decltype(id1 == id2)>{} );
+ static_assert( check_type<bool, decltype(id1 != id2)>{} );
+ static_assert( check_type<bool, decltype(id1 < id2)>{} );
+ static_assert( check_type<bool, decltype(id1 > id2)>{} );
+ static_assert( check_type<bool, decltype(id1 >= id2)>{} );
+ static_assert( check_type<bool, decltype(id1 <= id2)>{} );
+
+ static_assert( check_type<std::strong_ordering, decltype(id1 <=> id2)>{} );
+}