Reorder std::scoped_lock parameters as per P0739R0 DR status
authorJonathan Wakely <jwakely@redhat.com>
Sat, 15 Jul 2017 15:43:22 +0000 (16:43 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Sat, 15 Jul 2017 15:43:22 +0000 (16:43 +0100)
* include/std/mutex (scoped_lock): Reorder std::adopt_lock_t parameter
as per P0739R0.
* testsuite/30_threads/scoped_lock/cons/1.cc: Reorder arguments.
* testsuite/30_threads/scoped_lock/cons/deduction.cc: Test deduction
with std::adopt_lock_t.
* testsuite/30_threads/scoped_lock/requirements/typedefs.cc: Check
feature-test macro.

From-SVN: r250223

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/mutex
libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc
libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc
libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc

index 70d1944490e575ae34cc8ddbfe82c9577f6abe91..87b2f63d0ab9ae5cb67ada11d4b4ebfbdd0ba2ec 100644 (file)
@@ -1,3 +1,13 @@
+2017-07-15  Jonathan Wakely  <jwakely@redhat.com>
+
+       * include/std/mutex (scoped_lock): Reorder std::adopt_lock_t parameter
+       as per P0739R0.
+       * testsuite/30_threads/scoped_lock/cons/1.cc: Reorder arguments.
+       * testsuite/30_threads/scoped_lock/cons/deduction.cc: Test deduction
+       with std::adopt_lock_t.
+       * testsuite/30_threads/scoped_lock/requirements/typedefs.cc: Check
+       feature-test macro.
+
 2017-07-14  Jason Merrill  <jason@redhat.com>
            Jonathan Wakely  <jwakely@redhat.com>
 
index df48b4605711bee1c2e17d9d12e68244516a0df7..fadb9f60481ac19f9c5702695d3cedf9818ad1d6 100644 (file)
@@ -557,7 +557,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
 #if __cplusplus > 201402L
-#define __cpp_lib_scoped_lock 201703
+#define __cpp_lib_scoped_lock 201707
   /** @brief A scoped lock type for multiple lockable objects.
    *
    * A scoped_lock controls mutex ownership within a scope, releasing
@@ -570,7 +570,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       explicit scoped_lock(_MutexTypes&... __m) : _M_devices(std::tie(__m...))
       { std::lock(__m...); }
 
-      explicit scoped_lock(_MutexTypes&... __m, adopt_lock_t) noexcept
+      explicit scoped_lock(adopt_lock_t, _MutexTypes&... __m) noexcept
       : _M_devices(std::tie(__m...))
       { } // calling thread owns mutex
 
@@ -609,7 +609,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       explicit scoped_lock(mutex_type& __m) : _M_device(__m)
       { _M_device.lock(); }
 
-      explicit scoped_lock(mutex_type& __m, adopt_lock_t) noexcept
+      explicit scoped_lock(adopt_lock_t, mutex_type& __m) noexcept
       : _M_device(__m)
       { } // calling thread owns mutex
 
index 9f1b48c809a58fcc6876521ad4dad769183b669b..e420ab083789f0955680230da778450a15afd0d0 100644 (file)
@@ -79,7 +79,7 @@ void test01()
 
   try
     {
-      std::scoped_lock<BasicLockable> l(m, std::adopt_lock);
+      std::scoped_lock<BasicLockable> l(std::adopt_lock, m);
     }
   catch (...)
     {
@@ -113,7 +113,7 @@ void test02()
 
   try
     {
-      std::scoped_lock<Lockable<1>, Lockable<2>> l(m1, m2, std::adopt_lock);
+      std::scoped_lock<Lockable<1>, Lockable<2>> l(std::adopt_lock, m1, m2);
       VERIFY( m1.m.locked );
       VERIFY( m2.m.locked );
     }
index 399de7a5ae695c21cc24be2f4906bc6d4d2471a4..7d4f5bfc3865a38a75fe3008be40f37e4e89bc2d 100644 (file)
@@ -51,3 +51,28 @@ test01()
   std::scoped_lock l2(m2, m3);
   check_type<std::scoped_lock<Lockable, std::mutex>>(l2);
 }
+
+void
+test02()
+{
+  std::scoped_lock l0(std::adopt_lock);
+  check_type<std::scoped_lock<>>(l0);
+
+  struct BasicLockable {
+    void lock() { }
+    void unlock() { }
+  } m1;
+
+  std::scoped_lock l1(std::adopt_lock, m1);
+  check_type<std::scoped_lock<BasicLockable>>(l1);
+
+  struct Lockable {
+    void lock() { }
+    void unlock() { }
+    bool try_lock() { return true; }
+  } m2;
+
+  std::mutex m3;
+  std::scoped_lock l2(std::adopt_lock, m2, m3);
+  check_type<std::scoped_lock<Lockable, std::mutex>>(l2);
+}
index 55756d872623f1773ac8084a3e1253b303e4bf19..0a8903ebaab4683f5b62769eb01d3a93d1ac313e 100644 (file)
 
 #include <mutex>
 
+#ifndef __cpp_lib_scoped_lock
+# error "Feature-test macro for scoped_lock missing"
+#elif __cpp_lib_scoped_lock != 201707
+# error "Feature-test macro for scoped_lock has wrong value"
+#endif
+
 void test01()
 {
   // Check for required typedefs