From: Andrei Pavel Date: Fri, 7 Oct 2022 12:51:42 +0000 (+0300) Subject: [#2311] fix deprecated capture of 'this' in C++20 X-Git-Tag: Kea-2.3.2~36 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79989560796acd88d4b4c19c955ad75a673e9541;p=thirdparty%2Fkea.git [#2311] fix deprecated capture of 'this' in C++20 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 --- diff --git a/src/lib/util/readwrite_mutex.h b/src/lib/util/readwrite_mutex.h index f8766d5af4..4a6ecfe3fa 100644 --- a/src/lib/util/readwrite_mutex.h +++ b/src/lib/util/readwrite_mutex.h @@ -54,10 +54,10 @@ public: void writeLock() { std::unique_lock 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 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_; }