diff mbox series

[committed,2/2] libstdc++: Fix compilation of <stop_token> with Clang

Message ID 20200318130137.GO9441@redhat.com
State New
Headers show
Series [committed,1/2] libstdc++: Fix compilation with released versions of Clang | expand

Commit Message

Li, Pan2 via Gcc-patches March 18, 2020, 1:01 p.m. UTC
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.

Tested powerpc64le-linux, committed to master.
diff mbox series

Patch

commit e5de406f9967ef4b0bbdbcbc0320869d2bf04558
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Mar 18 12:55:29 2020 +0000

    libstdc++ Fix compilation of <stop_token> with Clang
    
    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.

diff --git a/libstdc++-v3/include/std/stop_token b/libstdc++-v3/include/std/stop_token
index 6fb8ae05197..87beb08c71d 100644
--- a/libstdc++-v3/include/std/stop_token
+++ b/libstdc++-v3/include/std/stop_token
@@ -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;