libstdc++ Fix compilation of <stop_token> with Clang
authorJonathan Wakely <jwakely@redhat.com>
Wed, 18 Mar 2020 12:55:29 +0000 (12:55 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 18 Mar 2020 12:55:29 +0000 (12:55 +0000)
Clang 9 supports C++20 via -std=c++2a but doesn't support three-way
comparisons, so <stop_token> fails to compile. When the compiler doesn't
support default comparisons, this patch defines operator== and
operator!= for the _Stop_state_ref class. That is enough for the header
to be compiled with Clang. It allows operator== for stop_token and
stop_source to work, but not operator!= because that isn't explicitly
defined.

* include/std/stop_token (stop_token::_Stop_state_ref): Define
comparison operators explicitly if the compiler won't synthesize them.

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/stop_token

index ae5fedbc66b0168ccfb2e807673a730529db7105..a9cd25992437647498781c3352229c995f6edf9e 100644 (file)
@@ -1,5 +1,8 @@
 2020-03-18  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/std/stop_token (stop_token::_Stop_state_ref): Define
+       comparison operators explicitly if the compiler won't synthesize them.
+
        * include/bits/stl_algobase.h (__lexicographical_compare_aux): Check
        __cpp_lib_concepts before using iter_reference_t.
        * include/bits/stream_iterator.h (istream_iterator): Check
index 6fb8ae05197c5bb4f45416c0213a34bba5cbd3ff..87beb08c71d908817ee324257a5e12559d6d431f 100644 (file)
@@ -456,8 +456,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       _Stop_state_t* operator->() const noexcept { return _M_ptr; }
 
+#if __cpp_impl_three_way_comparison >= 201907L
       friend bool
       operator==(const _Stop_state_ref&, const _Stop_state_ref&) = default;
+#else
+      friend bool
+      operator==(const _Stop_state_ref& __lhs, const _Stop_state_ref& __rhs)
+      noexcept
+      { return __lhs._M_ptr == __rhs._M_ptr; }
+
+      friend bool
+      operator!=(const _Stop_state_ref& __lhs, const _Stop_state_ref& __rhs)
+      noexcept
+      { return __lhs._M_ptr != __rhs._M_ptr; }
+#endif
 
     private:
       _Stop_state_t* _M_ptr = nullptr;