mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
Merge bitcoin/bitcoin#24169: build: Add --enable-c++20 option
999982b06c
build: Add --enable-c++20 option (MarcoFalke)fae679065e
Add CSerializedNetMsg::Copy() helper (MarcoFalke)fabb7c4ba6
Make fs.h C++20 compliant (MarcoFalke)fae2220f4e
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 ACK999982b06c
. Since last review was rebased, and enum-conversion change was dropped, and CSerializedNetMsg copy workaround was added fanquake: utACK999982b06c
Tree-SHA512: afc95ba03ea2b937017fc8e2b1449379cd2b6f7093c430d2e344c665a00c51e402d6651cbcbd0be8118ea1e54c3a86e67d2021d19ba1d4da67168e9fcb6b6f83
This commit is contained in:
commit
213e98ca82
6 changed files with 39 additions and 8 deletions
|
@ -11,4 +11,4 @@ export PACKAGES="clang llvm python3-zmq qtbase5-dev qttools5-dev-tools libevent-
|
||||||
export DOCKER_NAME_TAG=ubuntu:22.04
|
export DOCKER_NAME_TAG=ubuntu:22.04
|
||||||
export NO_DEPENDS=1
|
export NO_DEPENDS=1
|
||||||
export GOAL="install"
|
export GOAL="install"
|
||||||
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++"
|
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++"
|
||||||
|
|
10
configure.ac
10
configure.ac
|
@ -78,8 +78,18 @@ AC_ARG_WITH([seccomp],
|
||||||
[seccomp_found=$withval],
|
[seccomp_found=$withval],
|
||||||
[seccomp_found=auto])
|
[seccomp_found=auto])
|
||||||
|
|
||||||
|
AC_ARG_ENABLE([c++20],
|
||||||
|
[AS_HELP_STRING([--enable-c++20],
|
||||||
|
[enable compilation in c++20 mode (disabled by default)])],
|
||||||
|
[use_cxx20=$enableval],
|
||||||
|
[use_cxx20=no])
|
||||||
|
|
||||||
dnl Require C++17 compiler (no GNU extensions)
|
dnl Require C++17 compiler (no GNU extensions)
|
||||||
|
if test "$use_cxx20" = "no"; then
|
||||||
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
|
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
|
||||||
|
else
|
||||||
|
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
|
||||||
|
fi
|
||||||
|
|
||||||
dnl Check if -latomic is required for <std::atomic>
|
dnl Check if -latomic is required for <std::atomic>
|
||||||
CHECK_ATOMIC
|
CHECK_ATOMIC
|
||||||
|
|
18
src/fs.h
18
src/fs.h
|
@ -51,12 +51,26 @@ public:
|
||||||
// Disallow std::string conversion method to avoid locale-dependent encoding on windows.
|
// Disallow std::string conversion method to avoid locale-dependent encoding on windows.
|
||||||
std::string string() const = delete;
|
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 <fstream>.
|
// Required for path overloads in <fstream>.
|
||||||
// See https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=96e0367ead5d8dcac3bec2865582e76e2fbab190
|
// See https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=96e0367ead5d8dcac3bec2865582e76e2fbab190
|
||||||
path& make_preferred() { std::filesystem::path::make_preferred(); return *this; }
|
path& make_preferred() { std::filesystem::path::make_preferred(); return *this; }
|
||||||
path filename() const { return std::filesystem::path::filename(); }
|
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
|
// Disallow implicit std::string conversion for absolute to avoid
|
||||||
// locale-dependent encoding on windows.
|
// locale-dependent encoding on windows.
|
||||||
static inline path absolute(const path& p)
|
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
|
// use here, because these methods encode the path using C++'s narrow
|
||||||
// multibyte encoding, which on Windows corresponds to the current "code
|
// multibyte encoding, which on Windows corresponds to the current "code
|
||||||
// page", which is unpredictable and typically not able to represent all
|
// page", which is unpredictable and typically not able to represent all
|
||||||
// valid paths. So std::filesystem::path::u8string() and
|
// valid paths. So fs::path::u8string() and
|
||||||
// std::filesystem::u8path() functions are used instead on Windows. On
|
// fs::u8path() functions are used instead on Windows. On
|
||||||
// POSIX, u8string/u8path functions are not safe to use because paths are
|
// 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
|
// not always valid UTF-8, so plain string methods which do not transform
|
||||||
// the path there are used.
|
// the path there are used.
|
||||||
|
|
13
src/net.h
13
src/net.h
|
@ -99,15 +99,22 @@ struct AddedNodeInfo
|
||||||
class CNodeStats;
|
class CNodeStats;
|
||||||
class CClientUIInterface;
|
class CClientUIInterface;
|
||||||
|
|
||||||
struct CSerializedNetMsg
|
struct CSerializedNetMsg {
|
||||||
{
|
|
||||||
CSerializedNetMsg() = default;
|
CSerializedNetMsg() = default;
|
||||||
CSerializedNetMsg(CSerializedNetMsg&&) = default;
|
CSerializedNetMsg(CSerializedNetMsg&&) = default;
|
||||||
CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default;
|
CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default;
|
||||||
// No copying, only moves.
|
// No implicit copying, only moves.
|
||||||
CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
|
CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
|
||||||
CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;
|
CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;
|
||||||
|
|
||||||
|
CSerializedNetMsg Copy() const
|
||||||
|
{
|
||||||
|
CSerializedNetMsg copy;
|
||||||
|
copy.data = data;
|
||||||
|
copy.m_type = m_type;
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> data;
|
std::vector<unsigned char> data;
|
||||||
std::string m_type;
|
std::string m_type;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1624,7 +1624,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
|
||||||
hashBlock.ToString(), pnode->GetId());
|
hashBlock.ToString(), pnode->GetId());
|
||||||
|
|
||||||
const CSerializedNetMsg& ser_cmpctblock{lazy_ser.get()};
|
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;
|
state.pindexBestHeaderSent = pindex;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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)
|
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,
|
size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point& first,
|
||||||
|
|
Loading…
Add table
Reference in a new issue