Skip to content

Commit 213e98c

Browse files
committed
Merge bitcoin/bitcoin#24169: build: Add --enable-c++20 option
999982b build: Add --enable-c++20 option (MarcoFalke) fae6790 Add CSerializedNetMsg::Copy() helper (MarcoFalke) fabb7c4 Make fs.h C++20 compliant (MarcoFalke) fae2220 scheduler: Capture ‘this’ explicitly in lambda (MarcoFalke) Pull request description: This is for CI and devs only and doesn't change that C++17 is the standard we are currently using. The option `--enable-c++20` allows CI to check that the C++17 code in the repo is also valid C++20. (There are some cases where valid C++17 doesn't compile under C++20). Also, it allows developers to easily play with C++20 in the codebase. ACKs for top commit: ryanofsky: Code review ACK 999982b. Since last review was rebased, and enum-conversion change was dropped, and CSerializedNetMsg copy workaround was added fanquake: utACK 999982b Tree-SHA512: afc95ba03ea2b937017fc8e2b1449379cd2b6f7093c430d2e344c665a00c51e402d6651cbcbd0be8118ea1e54c3a86e67d2021d19ba1d4da67168e9fcb6b6f83
2 parents e7b6272 + 999982b commit 213e98c

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

ci/test/00_setup_env_native_asan.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ export PACKAGES="clang llvm python3-zmq qtbase5-dev qttools5-dev-tools libevent-
1111
export DOCKER_NAME_TAG=ubuntu:22.04
1212
export NO_DEPENDS=1
1313
export GOAL="install"
14-
export BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --with-gui=qt5 CPPFLAGS='-DARENA_DEBUG -DDEBUG_LOCKORDER' --with-sanitizers=address,integer,undefined CC=clang CXX=clang++"
14+
export BITCOIN_CONFIG="--enable-c++20 --enable-zmq --with-incompatible-bdb --with-gui=qt5 CPPFLAGS='-DARENA_DEBUG -DDEBUG_LOCKORDER' --with-sanitizers=address,integer,undefined CC=clang CXX=clang++"

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,18 @@ AC_ARG_WITH([seccomp],
7878
[seccomp_found=$withval],
7979
[seccomp_found=auto])
8080

81+
AC_ARG_ENABLE([c++20],
82+
[AS_HELP_STRING([--enable-c++20],
83+
[enable compilation in c++20 mode (disabled by default)])],
84+
[use_cxx20=$enableval],
85+
[use_cxx20=no])
86+
8187
dnl Require C++17 compiler (no GNU extensions)
88+
if test "$use_cxx20" = "no"; then
8289
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
90+
else
91+
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
92+
fi
8393

8494
dnl Check if -latomic is required for <std::atomic>
8595
CHECK_ATOMIC

src/fs.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,26 @@ class path : public std::filesystem::path
5151
// Disallow std::string conversion method to avoid locale-dependent encoding on windows.
5252
std::string string() const = delete;
5353

54+
std::string u8string() const
55+
{
56+
const auto& utf8_str{std::filesystem::path::u8string()};
57+
// utf8_str might either be std::string (C++17) or std::u8string
58+
// (C++20). Convert both to std::string. This method can be removed
59+
// after switching to C++20.
60+
return std::string{utf8_str.begin(), utf8_str.end()};
61+
}
62+
5463
// Required for path overloads in <fstream>.
5564
// See https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=96e0367ead5d8dcac3bec2865582e76e2fbab190
5665
path& make_preferred() { std::filesystem::path::make_preferred(); return *this; }
5766
path filename() const { return std::filesystem::path::filename(); }
5867
};
5968

69+
static inline path u8path(const std::string& utf8_str)
70+
{
71+
return std::filesystem::u8path(utf8_str);
72+
}
73+
6074
// Disallow implicit std::string conversion for absolute to avoid
6175
// locale-dependent encoding on windows.
6276
static inline path absolute(const path& p)
@@ -116,8 +130,8 @@ static inline std::string PathToString(const path& path)
116130
// use here, because these methods encode the path using C++'s narrow
117131
// multibyte encoding, which on Windows corresponds to the current "code
118132
// page", which is unpredictable and typically not able to represent all
119-
// valid paths. So std::filesystem::path::u8string() and
120-
// std::filesystem::u8path() functions are used instead on Windows. On
133+
// valid paths. So fs::path::u8string() and
134+
// fs::u8path() functions are used instead on Windows. On
121135
// POSIX, u8string/u8path functions are not safe to use because paths are
122136
// not always valid UTF-8, so plain string methods which do not transform
123137
// the path there are used.

src/net.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,22 @@ struct AddedNodeInfo
9999
class CNodeStats;
100100
class CClientUIInterface;
101101

102-
struct CSerializedNetMsg
103-
{
102+
struct CSerializedNetMsg {
104103
CSerializedNetMsg() = default;
105104
CSerializedNetMsg(CSerializedNetMsg&&) = default;
106105
CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default;
107-
// No copying, only moves.
106+
// No implicit copying, only moves.
108107
CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
109108
CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;
110109

110+
CSerializedNetMsg Copy() const
111+
{
112+
CSerializedNetMsg copy;
113+
copy.data = data;
114+
copy.m_type = m_type;
115+
return copy;
116+
}
117+
111118
std::vector<unsigned char> data;
112119
std::string m_type;
113120
};

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
16241624
hashBlock.ToString(), pnode->GetId());
16251625

16261626
const CSerializedNetMsg& ser_cmpctblock{lazy_ser.get()};
1627-
m_connman.PushMessage(pnode, CSerializedNetMsg{ser_cmpctblock.data, ser_cmpctblock.m_type});
1627+
m_connman.PushMessage(pnode, ser_cmpctblock.Copy());
16281628
state.pindexBestHeaderSent = pindex;
16291629
}
16301630
});

src/scheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static void Repeat(CScheduler& s, CScheduler::Function f, std::chrono::milliseco
111111

112112
void CScheduler::scheduleEvery(CScheduler::Function f, std::chrono::milliseconds delta)
113113
{
114-
scheduleFromNow([=] { Repeat(*this, f, delta); }, delta);
114+
scheduleFromNow([this, f, delta] { Repeat(*this, f, delta); }, delta);
115115
}
116116

117117
size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point& first,

0 commit comments

Comments
 (0)