public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Add <=> to thread::id
@ 2020-02-20 11:32 Jonathan Wakely
  2020-02-20 11:32 ` [committed] Remove std::type_info::operator!= for C++20 Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2020-02-20 11:32 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 319 bytes --]

	* 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.

This is a small part of P1614R2. Tested powerpc64le-linux, committed
to master.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 7290 bytes --]

commit c7b591f3868f778ce89b14cbfb81d8e96d0daad2
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Feb 7 20:28:06 2020 +0000

    libstdc++: Add <=> to thread::id
    
            * 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.

diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index b533bca578f..1f9c13ff7d1 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -45,7 +45,8 @@
 #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
@@ -96,17 +97,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
     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:
@@ -180,7 +186,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     void
     detach();
 
-    thread::id
+    id
     get_id() const noexcept
     { return _M_id; }
 
@@ -296,6 +302,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     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); }
@@ -319,6 +330,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   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.
@@ -424,8 +436,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   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}
@@ -498,7 +510,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     [[nodiscard]] static unsigned
     hardware_concurrency() noexcept
     {
-      return std::thread::hardware_concurrency();
+      return thread::hardware_concurrency();
     }
 
     [[nodiscard]] stop_source
@@ -544,7 +556,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       }
 
     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 @@
 
 #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;
diff --git a/libstdc++-v3/testsuite/30_threads/thread/id/operators.cc b/libstdc++-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 @@
 
 #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)>{} );
 }
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=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)>{} );
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [committed] Remove std::type_info::operator!= for C++20
  2020-02-20 11:32 [PATCH] libstdc++: Add <=> to thread::id Jonathan Wakely
@ 2020-02-20 11:32 ` Jonathan Wakely
  2020-02-20 13:02   ` [committed] libstdc++: Define operator<=> for <system_error> types Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2020-02-20 11:32 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 96 bytes --]

This is an even smaller part of P1614R2.

Tested powerpc64le-linux, committed to master.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 879 bytes --]

commit 20fa41e61fd2d2839ca47e0dfac6976c552ab648
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Feb 7 20:50:00 2020 +0000

    libstdc++: Remove std::type_info::operator!= for C++20
    
    This function can be synthesized by the compiler now.
    
            * libsupc++/typeinfo (type_info::operator!=): Remove for C++20.

diff --git a/libstdc++-v3/libsupc++/typeinfo b/libstdc++-v3/libsupc++/typeinfo
index 0f523d75b55..5a64e9ff092 100644
--- a/libstdc++-v3/libsupc++/typeinfo
+++ b/libstdc++-v3/libsupc++/typeinfo
@@ -133,8 +133,11 @@ namespace std
     { return __name == __arg.__name; }
   #endif
 #endif
+
+#if __cpp_impl_three_way_comparison < 201907L
     bool operator!=(const type_info& __arg) const _GLIBCXX_NOEXCEPT
     { return !operator==(__arg); }
+#endif
 
 #if __cplusplus >= 201103L
     size_t hash_code() const noexcept

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [committed] libstdc++: Define operator<=> for <system_error> types
  2020-02-20 11:32 ` [committed] Remove std::type_info::operator!= for C++20 Jonathan Wakely
@ 2020-02-20 13:02   ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2020-02-20 13:02 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1357 bytes --]

Another piece of P1614R2 for C++20.

This also adds tests for operator< in C++11, which was present but
untested.

         * include/std/system_error (error_category::operator<=>)
         (operator<=>(const error_code&, const error_code&))
         (operator<=>(const error_condition&, const error_condition&)): Define
         for C++20.
         * testsuite/19_diagnostics/error_category/operators/less.cc: New test.
         * testsuite/19_diagnostics/error_category/operators/three_way.cc: New
         test.
         * testsuite/19_diagnostics/error_code/operators/equal.cc: Remove
         incorrect comment.
         * testsuite/19_diagnostics/error_code/operators/less.cc: New test.
         * testsuite/19_diagnostics/error_code/operators/not_equal.cc: Remove
         incorrect comment.
         * testsuite/19_diagnostics/error_code/operators/three_way.cc: New test.
         * testsuite/19_diagnostics/error_condition/operators/equal.cc: Remove
         incorrect comment.
         * testsuite/19_diagnostics/error_condition/operators/less.cc: New test.
         * testsuite/19_diagnostics/error_condition/operators/not_equal.cc:
         Remove incorrect comment.
         * testsuite/19_diagnostics/error_condition/operators/three_way.cc: New
         test.


Tested powerpc64le-linux, committed to master.




[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 19397 bytes --]

commit 4be779f59b04947324889b7e1488fb9a68c81d53
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Feb 7 20:50:00 2020 +0000

    libstdc++: Define operator<=> for <system_error> types
    
    Another piece of P1614R2 for C++20.
    
    This also adds tests for operator< in C++11, which was present but
    untested.
    
            * include/std/system_error (error_category::operator<=>)
            (operator<=>(const error_code&, const error_code&))
            (operator<=>(const error_condition&, const error_condition&)): Define
            for C++20.
            * testsuite/19_diagnostics/error_category/operators/less.cc: New test.
            * testsuite/19_diagnostics/error_category/operators/three_way.cc: New
            test.
            * testsuite/19_diagnostics/error_code/operators/equal.cc: Remove
            incorrect comment.
            * testsuite/19_diagnostics/error_code/operators/less.cc: New test.
            * testsuite/19_diagnostics/error_code/operators/not_equal.cc: Remove
            incorrect comment.
            * testsuite/19_diagnostics/error_code/operators/three_way.cc: New test.
            * testsuite/19_diagnostics/error_condition/operators/equal.cc: Remove
            incorrect comment.
            * testsuite/19_diagnostics/error_condition/operators/less.cc: New test.
            * testsuite/19_diagnostics/error_condition/operators/not_equal.cc:
            Remove incorrect comment.
            * testsuite/19_diagnostics/error_condition/operators/three_way.cc: New
            test.

diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error
index f1aebd59d02..f92b4345895 100644
--- a/libstdc++-v3/include/std/system_error
+++ b/libstdc++-v3/include/std/system_error
@@ -39,6 +39,9 @@
 #include <bits/error_constants.h>
 #include <iosfwd>
 #include <stdexcept>
+#if __cplusplus > 201703L
+# include <compare>
+#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -129,17 +132,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     virtual bool
     equivalent(const error_code& __code, int __i) const noexcept;
 
-    bool
-    operator<(const error_category& __other) const noexcept
-    { return less<const error_category*>()(this, &__other); }
-
     bool
     operator==(const error_category& __other) const noexcept
     { return this == &__other; }
 
+#if __cpp_lib_three_way_comparison
+    strong_ordering
+    operator<=>(const error_category& __rhs) const noexcept
+    { return std::compare_three_way()(this, &__rhs); }
+#else
     bool
     operator!=(const error_category& __other) const noexcept
     { return this != &__other; }
+
+    bool
+    operator<(const error_category& __other) const noexcept
+    { return less<const error_category*>()(this, &__other); }
+#endif
   };
 
   // DR 890.
@@ -230,6 +239,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   make_error_code(errc __e) noexcept
   { return error_code(static_cast<int>(__e), generic_category()); }
 
+#if __cpp_lib_three_way_comparison
+  inline strong_ordering
+  operator<=>(const error_code& __lhs, const error_code& __rhs) noexcept
+  {
+    if (auto __c = __lhs.category() <=> __rhs.category(); __c != 0)
+      return __c;
+    return __lhs.value() <=> __rhs.value();
+  }
+#else
   inline bool
   operator<(const error_code& __lhs, const error_code& __rhs) noexcept
   {
@@ -237,6 +255,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    || (__lhs.category() == __rhs.category()
 		&& __lhs.value() < __rhs.value()));
   }
+#endif
 
   template<typename _CharT, typename _Traits>
     basic_ostream<_CharT, _Traits>&
@@ -316,17 +335,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   make_error_condition(errc __e) noexcept
   { return error_condition(static_cast<int>(__e), generic_category()); }
 
-  /// Define an ordering for error_condition objects.
-  /// @relates error_condition
-  inline bool
-  operator<(const error_condition& __lhs,
-	    const error_condition& __rhs) noexcept
-  {
-    return (__lhs.category() < __rhs.category()
-	    || (__lhs.category() == __rhs.category()
-		&& __lhs.value() < __rhs.value()));
-  }
-
   // 19.4.4 Comparison operators
 
   /// @relates error_code
@@ -344,15 +352,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    || __rhs.category().equivalent(__lhs, __rhs.value()));
   }
 
-  /// @relates error_code
-  /// @relates error_condition
-  inline bool
-  operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
-  {
-    return (__rhs.category().equivalent(__rhs.value(), __lhs)
-	    || __lhs.category().equivalent(__rhs, __lhs.value()));
-  }
-
   /// @relates error_condition
   inline bool
   operator==(const error_condition& __lhs,
@@ -362,6 +361,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    && __lhs.value() == __rhs.value());
   }
 
+#if __cpp_lib_three_way_comparison
+  /// Define an ordering for error_condition objects.
+  /// @relates error_condition
+  inline strong_ordering
+  operator<=>(const error_condition& __lhs,
+	      const error_condition& __rhs) noexcept
+  {
+    if (auto __c = __lhs.category() <=> __rhs.category(); __c != 0)
+      return __c;
+    return __lhs.value() <=> __rhs.value();
+  }
+#else
+  /// Define an ordering for error_condition objects.
+  /// @relates error_condition
+  inline bool
+  operator<(const error_condition& __lhs,
+	    const error_condition& __rhs) noexcept
+  {
+    return (__lhs.category() < __rhs.category()
+	    || (__lhs.category() == __rhs.category()
+		&& __lhs.value() < __rhs.value()));
+  }
+
+  /// @relates error_code
+  /// @relates error_condition
+  inline bool
+  operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
+  {
+    return (__rhs.category().equivalent(__rhs.value(), __lhs)
+	    || __lhs.category().equivalent(__rhs, __lhs.value()));
+  }
+
   /// @relates error_code
   inline bool
   operator!=(const error_code& __lhs, const error_code& __rhs) noexcept
@@ -384,7 +415,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   operator!=(const error_condition& __lhs,
 	     const error_condition& __rhs) noexcept
   { return !(__lhs == __rhs); }
-
+#endif // three_way_comparison
 
   /**
    * @brief An exception type that includes an `error_code` value.
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/less.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/less.cc
new file mode 100644
index 00000000000..67831536b85
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/less.cc
@@ -0,0 +1,30 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-static-libgcc" { target *-*-mingw* } }
+
+// 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 <system_error>
+#include <testsuite_error.h>
+
+int main()
+{
+  __gnu_test::test_category c1;
+  VERIFY( !(c1 < c1) );
+  __gnu_test::test_derived_category c2;
+  VERIFY( (c1 < c2) || (c2 < c1) );
+}
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/three_way.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/three_way.cc
new file mode 100644
index 00000000000..efdf320dd36
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/operators/three_way.cc
@@ -0,0 +1,48 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <system_error>
+#include <testsuite_error.h>
+
+void
+test01()
+{
+  __gnu_test::test_category c1;
+  VERIFY( std::is_eq(c1 <=> c1) );
+  __gnu_test::test_derived_category c2;
+  VERIFY( std::is_neq(c1 <=> c2) );
+}
+
+void
+test02()
+{
+  __gnu_test::test_category c1;
+  VERIFY( c1 <= c1 );
+  VERIFY( c1 >= c1 );
+  __gnu_test::test_derived_category c2;
+  VERIFY( (c1 < c2) || (c2 < c1) );
+  VERIFY( (c1 > c2) || (c2 > c1) );
+}
+
+int main()
+{
+  test01();
+  test02();
+}
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc
index 5011c754fac..edb68b295ff 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/equal.cc
@@ -22,7 +22,6 @@
 #include <system_error>
 #include <testsuite_error.h>
 
-// unspecified bool operator positive tests
 int main()
 {
   std::error_code e1;
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc
new file mode 100644
index 00000000000..8cb3a7c3a7a
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc
@@ -0,0 +1,38 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-static-libstdc++" { target *-*-mingw* } }
+
+// 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 <system_error>
+#include <testsuite_error.h>
+
+int main()
+{
+  std::error_code e1;
+  std::error_code e2(std::make_error_code(std::errc::operation_not_supported));
+
+  VERIFY( !(e1 < e1) );
+  VERIFY( !(e2 < e2) );
+
+  VERIFY( (e1 < e2) == (e1.value() < e2.value()) );
+
+  const __gnu_test::test_category cat;
+  std::error_code e3(e2.value(), cat);
+  VERIFY( !(e3 < e3) );
+  VERIFY( (e2 < e3) == (e2.category() < e3.category()) );
+}
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc
index 7bc5b6d6882..5f261ed56fe 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc
@@ -22,7 +22,6 @@
 #include <system_error>
 #include <testsuite_error.h>
 
-// unspecified bool operator positive tests
 int main()
 {
   std::error_code e1;
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/three_way.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/three_way.cc
new file mode 100644
index 00000000000..86416d6dbbd
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/three_way.cc
@@ -0,0 +1,60 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <system_error>
+#include <testsuite_error.h>
+
+void
+test01()
+{
+  std::error_code e1;
+  std::error_code e2(std::make_error_code(std::errc::operation_not_supported));
+
+  VERIFY( std::is_eq(e1 <=> e1) );
+  VERIFY( std::is_lteq(e1 <=> e1) );
+  VERIFY( std::is_gteq(e1 <=> e1) );
+
+  VERIFY( std::is_neq(e1 <=> e2) );
+  VERIFY( std::is_lt(e1 <=> e2) || std::is_gt(e1 <=> e2) );
+  VERIFY( (e1 <=> e2) == (e1.value() <=> e2.value()) );
+
+  VERIFY( e1 == e1 );
+  VERIFY( !(e1 == e2) );
+
+  VERIFY( !(e1 < e1) );
+  VERIFY( !(e2 < e2) );
+
+  const __gnu_test::test_category cat;
+  std::error_code e3(e2.value(), cat);
+
+  VERIFY( std::is_neq(e2 <=> e3) );
+  VERIFY( std::is_lt(e2 <=> e3) || std::is_gt(e2 <=> e3) );
+  VERIFY( (e2 <=> e3) == (e2.category() <=> e3.category()) );
+
+  VERIFY( !(e2 == e3) );
+
+  VERIFY( !(e3 < e3) );
+  VERIFY( (e2 < e3) == (e2.category() < e3.category()) );
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/equal.cc
index 7fd3f7ec204..2c97fe201b5 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/equal.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/equal.cc
@@ -21,7 +21,6 @@
 #include <system_error>
 #include <testsuite_error.h>
 
-// unspecified bool operator positive tests
 void test01()
 {
   std::error_condition e1;
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc
new file mode 100644
index 00000000000..20b32866565
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc
@@ -0,0 +1,38 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-static-libstdc++" { target *-*-mingw* } }
+
+// 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 <system_error>
+#include <testsuite_error.h>
+
+int main()
+{
+  std::error_condition e1;
+  std::error_condition e2(std::errc::operation_not_supported);
+
+  VERIFY( !(e1 < e1) );
+  VERIFY( !(e2 < e2) );
+
+  VERIFY( (e1 < e2) == (e1.value() < e2.value()) );
+
+  const __gnu_test::test_category cat;
+  std::error_condition e3(e2.value(), cat);
+  VERIFY( !(e3 < e3) );
+  VERIFY( (e2 < e3) == (e2.category() < e3.category()) );
+}
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/not_equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/not_equal.cc
index 84cd92cc169..238fabbcc20 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/not_equal.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/not_equal.cc
@@ -21,7 +21,6 @@
 #include <system_error>
 #include <testsuite_error.h>
 
-// unspecified bool operator positive tests
 void test01()
 {
   std::error_condition e1;
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/three_way.cc b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/three_way.cc
new file mode 100644
index 00000000000..48c1671bdba
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/three_way.cc
@@ -0,0 +1,60 @@
+// 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/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <system_error>
+#include <testsuite_error.h>
+
+void
+test01()
+{
+  std::error_condition e1;
+  std::error_condition e2(std::errc::operation_not_supported);
+
+  VERIFY( std::is_eq(e1 <=> e1) );
+  VERIFY( std::is_lteq(e1 <=> e1) );
+  VERIFY( std::is_gteq(e1 <=> e1) );
+
+  VERIFY( std::is_neq(e1 <=> e2) );
+  VERIFY( std::is_lt(e1 <=> e2) || std::is_gt(e1 <=> e2) );
+  VERIFY( (e1 <=> e2) == (e1.value() <=> e2.value()) );
+
+  VERIFY( e1 == e1 );
+  VERIFY( !(e1 == e2) );
+
+  VERIFY( !(e1 < e1) );
+  VERIFY( !(e2 < e2) );
+
+  const __gnu_test::test_category cat;
+  std::error_condition e3(e2.value(), cat);
+
+  VERIFY( std::is_neq(e2 <=> e3) );
+  VERIFY( std::is_lt(e2 <=> e3) || std::is_gt(e2 <=> e3) );
+  VERIFY( (e2 <=> e3) == (e2.category() <=> e3.category()) );
+
+  VERIFY( !(e2 == e3) );
+
+  VERIFY( !(e3 < e3) );
+  VERIFY( (e2 < e3) == (e2.category() < e3.category()) );
+}
+
+int main()
+{
+  test01();
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-20 13:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20 11:32 [PATCH] libstdc++: Add <=> to thread::id Jonathan Wakely
2020-02-20 11:32 ` [committed] Remove std::type_info::operator!= for C++20 Jonathan Wakely
2020-02-20 13:02   ` [committed] libstdc++: Define operator<=> for <system_error> types Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).