From fae2220f4e48934313389864d3d362f672627eb8 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 17 Mar 2022 21:24:26 +0100 Subject: =?UTF-8?q?scheduler:=20Capture=20=E2=80=98this=E2=80=99=20explici?= =?UTF-8?q?tly=20in=20lambda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without the changes, g++ will warn to compile under C++20: scheduler.cpp:114:21: warning: implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20 [-Wdeprecated] 114 | scheduleFromNow([=] { Repeat(*this, f, delta); }, delta); | ^ scheduler.cpp:114:21: note: add explicit ‘this’ or ‘*this’ capture --- src/scheduler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 0b2ad3c553..197d009f7c 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -111,7 +111,7 @@ static void Repeat(CScheduler& s, CScheduler::Function f, std::chrono::milliseco void CScheduler::scheduleEvery(CScheduler::Function f, std::chrono::milliseconds delta) { - scheduleFromNow([=] { Repeat(*this, f, delta); }, delta); + scheduleFromNow([this, f, delta] { Repeat(*this, f, delta); }, delta); } size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point& first, -- cgit v1.2.3 From fabb7c4ba629ecdea80a23674e2659d3d391565f Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 11 Mar 2022 11:21:13 +0100 Subject: Make fs.h C++20 compliant Without the changes, the file will fail to compile under C++20 because char8_t can not be converted to char implicitly. --- src/fs.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/fs.h b/src/fs.h index 00b786453c..8e145cbb8e 100644 --- a/src/fs.h +++ b/src/fs.h @@ -51,12 +51,26 @@ public: // Disallow std::string conversion method to avoid locale-dependent encoding on windows. std::string string() const = delete; + std::string u8string() const + { + const auto& utf8_str{std::filesystem::path::u8string()}; + // utf8_str might either be std::string (C++17) or std::u8string + // (C++20). Convert both to std::string. This method can be removed + // after switching to C++20. + return std::string{utf8_str.begin(), utf8_str.end()}; + } + // Required for path overloads in . // See https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=96e0367ead5d8dcac3bec2865582e76e2fbab190 path& make_preferred() { std::filesystem::path::make_preferred(); return *this; } path filename() const { return std::filesystem::path::filename(); } }; +static inline path u8path(const std::string& utf8_str) +{ + return std::filesystem::u8path(utf8_str); +} + // Disallow implicit std::string conversion for absolute to avoid // locale-dependent encoding on windows. static inline path absolute(const path& p) @@ -116,8 +130,8 @@ static inline std::string PathToString(const path& path) // use here, because these methods encode the path using C++'s narrow // multibyte encoding, which on Windows corresponds to the current "code // page", which is unpredictable and typically not able to represent all - // valid paths. So std::filesystem::path::u8string() and - // std::filesystem::u8path() functions are used instead on Windows. On + // valid paths. So fs::path::u8string() and + // fs::u8path() functions are used instead on Windows. On // POSIX, u8string/u8path functions are not safe to use because paths are // not always valid UTF-8, so plain string methods which do not transform // the path there are used. -- cgit v1.2.3 From fae679065e4ef0c6383bbdd1876aaed6c1e40104 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 24 Mar 2022 11:44:08 +0100 Subject: Add CSerializedNetMsg::Copy() helper This makes code that uses the helper less verbose. Moreover, this makes net_processing C++20 compliant. Otherwise, it would lead to a compile error (see below). C++20 disables aggregate initialization when any constructor is declared. See http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1008r1.pdf net_processing.cpp:1627:42: error: no matching constructor for initialization of 'CSerializedNetMsg' m_connman.PushMessage(pnode, CSerializedNetMsg{ser_cmpctblock.data, ser_cmpctblock.m_type}); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/net.h | 13 ++++++++++--- src/net_processing.cpp | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/net.h b/src/net.h index a38310938b..05e71072e6 100644 --- a/src/net.h +++ b/src/net.h @@ -99,15 +99,22 @@ struct AddedNodeInfo class CNodeStats; class CClientUIInterface; -struct CSerializedNetMsg -{ +struct CSerializedNetMsg { CSerializedNetMsg() = default; CSerializedNetMsg(CSerializedNetMsg&&) = default; CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default; - // No copying, only moves. + // No implicit copying, only moves. CSerializedNetMsg(const CSerializedNetMsg& msg) = delete; CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete; + CSerializedNetMsg Copy() const + { + CSerializedNetMsg copy; + copy.data = data; + copy.m_type = m_type; + return copy; + } + std::vector data; std::string m_type; }; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 77efac3364..34dd7991be 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1624,7 +1624,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha hashBlock.ToString(), pnode->GetId()); const CSerializedNetMsg& ser_cmpctblock{lazy_ser.get()}; - m_connman.PushMessage(pnode, CSerializedNetMsg{ser_cmpctblock.data, ser_cmpctblock.m_type}); + m_connman.PushMessage(pnode, ser_cmpctblock.Copy()); state.pindexBestHeaderSent = pindex; } }); -- cgit v1.2.3