]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2311] fix deprecated capture of 'this' in C++20
authorAndrei Pavel <andrei@isc.org>
Fri, 7 Oct 2022 12:51:42 +0000 (15:51 +0300)
committerAndrei Pavel <andrei@isc.org>
Fri, 21 Oct 2022 14:45:24 +0000 (17:45 +0300)
In file included from readwrite_mutex_unittest.cc:9:
../../../../src/lib/util/readwrite_mutex.h: In lambda function:
../../../../src/lib/util/readwrite_mutex.h:57:25: warning: implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20 [-Wdeprecated]
   57 |         gate1_.wait(lk, [=]() { return (!writeEntered()); });
      |                         ^
../../../../src/lib/util/readwrite_mutex.h:57:25: note: add explicit ‘this’ or ‘*this’ capture
../../../../src/lib/util/readwrite_mutex.h: In lambda function:
../../../../src/lib/util/readwrite_mutex.h:60:25: warning: implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20 [-Wdeprecated]
   60 |         gate2_.wait(lk, [=]() { return (readers() == 0); });
      |                         ^
../../../../src/lib/util/readwrite_mutex.h:60:25: note: add explicit ‘this’ or ‘*this’ capture
../../../../src/lib/util/readwrite_mutex.h: In lambda function:
../../../../src/lib/util/readwrite_mutex.h:77:25: warning: implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20 [-Wdeprecated]
   77 |         gate1_.wait(lk, [=]() { return (state_ < MAX_READERS); });
      |                         ^
../../../../src/lib/util/readwrite_mutex.h:77:25: note: add explicit ‘this’ or ‘*this’ capture

src/lib/util/readwrite_mutex.h

index f8766d5af42f2cd9e52c3681b9ca8723ca7d8a99..4a6ecfe3fa906546954e7346316a914ad31f8fab 100644 (file)
@@ -54,10 +54,10 @@ public:
     void writeLock() {
         std::unique_lock<std::mutex> lk(mutex_);
         // Wait until the write entered flag can be set.
-        gate1_.wait(lk, [=]() { return (!writeEntered()); });
+        gate1_.wait(lk, [=, this]() { return (!writeEntered()); });
         state_ |= WRITE_ENTERED;
         // Wait until there are no more readers.
-        gate2_.wait(lk, [=]() { return (readers() == 0); });
+        gate2_.wait(lk, [=, this]() { return (readers() == 0); });
     }
 
     /// @brief Unlock write.
@@ -74,7 +74,7 @@ public:
     void readLock() {
         std::unique_lock<std::mutex> lk(mutex_);
         // Wait if there is a writer or if readers overflow.
-        gate1_.wait(lk, [=]() { return (state_ < MAX_READERS); });
+        gate1_.wait(lk, [=, this]() { return (state_ < MAX_READERS); });
         ++state_;
     }