Skip to content

Commit 3e69125

Browse files
committed
Merge bitcoin#28349: build: Require C++20 compiler
fa6e50d fuzz: Use C++20 starts_with in rpc.cpp (MarcoFalke) faa4838 Revert "tracepoints: Disables `-Wgnu-zero-variadic-macro-arguments` to compile without warnings" (MarcoFalke) fae3b77 refactor: Drop unused _Pragma to ignore -Wgnu-zero-variadic-macro-arguments (MarcoFalke) fa02fc0 refactor: modernize-use-default-member-init for bit-fields (C++20) (MarcoFalke) fa67f09 build: Require C++20 compiler (MarcoFalke) Pull request description: C++20 allows to write safer code, because it allows to enforce more stuff at compile time (`constinit`, `conteval`, `constexpr`, `std::span`, ...). Also, it allows to write less verbose and easier to understand code (C++ 20 Concepts). See bitcoin#23363 and https://en.cppreference.com/w/cpp/compiler_support#cpp20 With g++-10 (bitcoin#28348) and clang-13 (bitcoin#28210), there is broad support for almost all features of C++20. It should be fine to require a C++20 compiler for Bitcoin Core 27.0 in 2024 (next year), not the soon upcoming 26.0 next month. This pull request includes three small cleanups to make use of C++20 features. If any issues are detected before or after merge, this should be easy to revert. If no issues arise, it should be fine to make use of more involved C++20 features later on. ACKs for top commit: fanquake: ACK fa6e50d Tree-SHA512: 244d79bfb0b750a4bdd713f40573b9ca33816fb84b6c84a58f027b9d7d4bb0cc4f18642959e4cf3d094808a69e5b8a327ca8521d7c0c08af27dacb5da3e78e71
2 parents 03042fb + fa6e50d commit 3e69125

File tree

11 files changed

+26
-51
lines changed

11 files changed

+26
-51
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ jobs:
6262
echo "TEST_BASE=$(git rev-list -n$((${{ env.MAX_COUNT }} + 1)) --reverse HEAD ^$(git rev-list -n1 --merges HEAD)^@ | head -1)" >> "$GITHUB_ENV"
6363
- run: |
6464
sudo apt-get update
65-
sudo apt-get install clang ccache build-essential libtool autotools-dev automake pkg-config bsdmainutils python3-zmq libevent-dev libboost-dev libsqlite3-dev libdb++-dev systemtap-sdt-dev libminiupnpc-dev libnatpmp-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools qtwayland5 libqrencode-dev -y
65+
sudo apt-get install clang-15 ccache build-essential libtool autotools-dev automake pkg-config bsdmainutils python3-zmq libevent-dev libboost-dev libsqlite3-dev libdb++-dev systemtap-sdt-dev libminiupnpc-dev libnatpmp-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools qtwayland5 libqrencode-dev -y
6666
- name: Compile and run tests
6767
run: |
6868
# Run tests on commits after the last merge commit and before the PR head commit
6969
# Use clang++, because it is a bit faster and uses less memory than g++
70-
git rebase --exec "echo Running test-one-commit on \$( git log -1 ) && ./autogen.sh && CC=clang CXX=clang++ ./configure && make clean && make -j $(nproc) check && ./test/functional/test_runner.py -j $(( $(nproc) * 2 ))" ${{ env.TEST_BASE }}
70+
git rebase --exec "echo Running test-one-commit on \$( git log -1 ) && ./autogen.sh && CC=clang-15 CXX=clang++-15 ./configure && make clean && make -j $(nproc) check && ./test/functional/test_runner.py -j $(( $(nproc) * 2 ))" ${{ env.TEST_BASE }}
7171
7272
macos-native-x86_64:
7373
name: 'macOS 13 native, x86_64, no depends, sqlite only, gui'

build-aux/m4/ax_cxx_compile_stdcxx.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
983983
984984
#error "This is not a C++ compiler"
985985
986-
#elif __cplusplus < 202002L
986+
#elif __cplusplus < 201709L // Temporary patch on top of upstream to allow g++-10
987987
988988
#error "This is not a C++20 compiler"
989989

configure.ac

+1-11
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,8 @@ case $host in
9696
;;
9797
esac
9898

99-
AC_ARG_ENABLE([c++20],
100-
[AS_HELP_STRING([--enable-c++20],
101-
[enable compilation in c++20 mode (disabled by default)])],
102-
[use_cxx20=$enableval],
103-
[use_cxx20=no])
104-
105-
dnl Require C++17 compiler (no GNU extensions)
106-
if test "$use_cxx20" = "no"; then
107-
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
108-
else
99+
dnl Require C++20 compiler (no GNU extensions)
109100
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
110-
fi
111101

112102
dnl Unless the user specified OBJCXX, force it to be the same as CXX. This ensures
113103
dnl that we get the same -std flags for both.

depends/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ NO_HARDEN ?=
4949
FALLBACK_DOWNLOAD_PATH ?= https://bitcoincore.org/depends-sources
5050

5151
C_STANDARD ?= c11
52-
CXX_STANDARD ?= c++17
52+
CXX_STANDARD ?= c++20
5353

5454
BUILD = $(shell ./config.guess)
5555
HOST ?= $(BUILD)

depends/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The following can be set when running make: `make FOO=bar`
9898
- `SDK_PATH`: Path where SDKs can be found (used by macOS)
9999
- `FALLBACK_DOWNLOAD_PATH`: If a source file can't be fetched, try here before giving up
100100
- `C_STANDARD`: Set the C standard version used. Defaults to `c11`.
101-
- `CXX_STANDARD`: Set the C++ standard version used. Defaults to `c++17`.
101+
- `CXX_STANDARD`: Set the C++ standard version used. Defaults to `c++20`.
102102
- `NO_BOOST`: Don't download/build/cache Boost
103103
- `NO_LIBEVENT`: Don't download/build/cache Libevent
104104
- `NO_QT`: Don't download/build/cache Qt and its dependencies

depends/packages/qt.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $(package)_config_opts_release += -silent
4141
$(package)_config_opts_debug = -debug
4242
$(package)_config_opts_debug += -optimized-tools
4343
$(package)_config_opts += -bindir $(build_prefix)/bin
44-
$(package)_config_opts += -c++std c++17
44+
$(package)_config_opts += -c++std c++2a
4545
$(package)_config_opts += -confirm-license
4646
$(package)_config_opts += -hostprefix $(build_prefix)
4747
$(package)_config_opts += -no-compile-examples

src/.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ SpacesInAngles: false
4343
SpacesInContainerLiterals: true
4444
SpacesInCStyleCastParentheses: false
4545
SpacesInParentheses: false
46-
Standard: c++17
46+
Standard: c++20
4747
UseTab: Never

src/test/fuzz/fuzz.h

-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ struct FuzzTargetOptions {
3333

3434
void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, FuzzTargetOptions opts);
3535

36-
#if defined(__clang__)
37-
#define FUZZ_TARGET(...) _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"") DETAIL_FUZZ(__VA_ARGS__) _Pragma("clang diagnostic pop")
38-
#else
3936
#define FUZZ_TARGET(...) DETAIL_FUZZ(__VA_ARGS__)
40-
#endif
4137

4238
#define DETAIL_FUZZ(name, ...) \
4339
void name##_fuzz_target(FuzzBufferType); \

src/test/fuzz/rpc.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,7 @@ FUZZ_TARGET(rpc, .init = initialize_rpc)
380380
rpc_testing_setup->CallRPC(rpc_command, arguments);
381381
} catch (const UniValue& json_rpc_error) {
382382
const std::string error_msg{json_rpc_error.find_value("message").get_str()};
383-
// Once c++20 is allowed, starts_with can be used.
384-
// if (error_msg.starts_with("Internal bug detected")) {
385-
if (0 == error_msg.rfind("Internal bug detected", 0)) {
383+
if (error_msg.starts_with("Internal bug detected")) {
386384
// Only allow the intentional internal bug
387385
assert(error_msg.find("trigger_internal_bug") != std::string::npos);
388386
}

src/txrequest.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct Announcement {
7373
const bool m_is_wtxid : 1;
7474

7575
/** What state this announcement is in. */
76-
State m_state : 3;
76+
State m_state : 3 {State::CANDIDATE_DELAYED};
7777
State GetState() const { return m_state; }
7878
void SetState(State state) { m_state = state; }
7979

@@ -97,9 +97,9 @@ struct Announcement {
9797

9898
/** Construct a new announcement from scratch, initially in CANDIDATE_DELAYED state. */
9999
Announcement(const GenTxid& gtxid, NodeId peer, bool preferred, std::chrono::microseconds reqtime,
100-
SequenceNumber sequence) :
101-
m_txhash(gtxid.GetHash()), m_time(reqtime), m_peer(peer), m_sequence(sequence), m_preferred(preferred),
102-
m_is_wtxid{gtxid.IsWtxid()}, m_state{State::CANDIDATE_DELAYED} {}
100+
SequenceNumber sequence)
101+
: m_txhash(gtxid.GetHash()), m_time(reqtime), m_peer(peer), m_sequence(sequence), m_preferred(preferred),
102+
m_is_wtxid{gtxid.IsWtxid()} {}
103103
};
104104

105105
//! Type alias for priorities.

src/util/trace.h

+13-22
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,19 @@
1313

1414
#include <sys/sdt.h>
1515

16-
// Disabling this warning can be removed once we switch to C++20
17-
#if defined(__clang__) && __cplusplus < 202002L
18-
#define BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"")
19-
#define BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP _Pragma("clang diagnostic pop")
20-
#else
21-
#define BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH
22-
#define BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
23-
#endif
24-
25-
#define TRACE(context, event) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE(context, event) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
26-
#define TRACE1(context, event, a) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE1(context, event, a) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
27-
#define TRACE2(context, event, a, b) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE2(context, event, a, b) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
28-
#define TRACE3(context, event, a, b, c) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE3(context, event, a, b, c) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
29-
#define TRACE4(context, event, a, b, c, d) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE4(context, event, a, b, c, d) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
30-
#define TRACE5(context, event, a, b, c, d, e) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE5(context, event, a, b, c, d, e) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
31-
#define TRACE6(context, event, a, b, c, d, e, f) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE6(context, event, a, b, c, d, e, f) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
32-
#define TRACE7(context, event, a, b, c, d, e, f, g) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE7(context, event, a, b, c, d, e, f, g) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
33-
#define TRACE8(context, event, a, b, c, d, e, f, g, h) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE8(context, event, a, b, c, d, e, f, g, h) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
34-
#define TRACE9(context, event, a, b, c, d, e, f, g, h, i) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE9(context, event, a, b, c, d, e, f, g, h, i) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
35-
#define TRACE10(context, event, a, b, c, d, e, f, g, h, i, j) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE10(context, event, a, b, c, d, e, f, g, h, i, j) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
36-
#define TRACE11(context, event, a, b, c, d, e, f, g, h, i, j, k) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE11(context, event, a, b, c, d, e, f, g, h, i, j, k) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
37-
#define TRACE12(context, event, a, b, c, d, e, f, g, h, i, j, k, l) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_PUSH DTRACE_PROBE12(context, event, a, b, c, d, e, f, g, h, i, j, k, l) BITCOIN_DISABLE_WARN_ZERO_VARIADIC_POP
16+
#define TRACE(context, event) DTRACE_PROBE(context, event)
17+
#define TRACE1(context, event, a) DTRACE_PROBE1(context, event, a)
18+
#define TRACE2(context, event, a, b) DTRACE_PROBE2(context, event, a, b)
19+
#define TRACE3(context, event, a, b, c) DTRACE_PROBE3(context, event, a, b, c)
20+
#define TRACE4(context, event, a, b, c, d) DTRACE_PROBE4(context, event, a, b, c, d)
21+
#define TRACE5(context, event, a, b, c, d, e) DTRACE_PROBE5(context, event, a, b, c, d, e)
22+
#define TRACE6(context, event, a, b, c, d, e, f) DTRACE_PROBE6(context, event, a, b, c, d, e, f)
23+
#define TRACE7(context, event, a, b, c, d, e, f, g) DTRACE_PROBE7(context, event, a, b, c, d, e, f, g)
24+
#define TRACE8(context, event, a, b, c, d, e, f, g, h) DTRACE_PROBE8(context, event, a, b, c, d, e, f, g, h)
25+
#define TRACE9(context, event, a, b, c, d, e, f, g, h, i) DTRACE_PROBE9(context, event, a, b, c, d, e, f, g, h, i)
26+
#define TRACE10(context, event, a, b, c, d, e, f, g, h, i, j) DTRACE_PROBE10(context, event, a, b, c, d, e, f, g, h, i, j)
27+
#define TRACE11(context, event, a, b, c, d, e, f, g, h, i, j, k) DTRACE_PROBE11(context, event, a, b, c, d, e, f, g, h, i, j, k)
28+
#define TRACE12(context, event, a, b, c, d, e, f, g, h, i, j, k, l) DTRACE_PROBE12(context, event, a, b, c, d, e, f, g, h, i, j, k, l)
3829

3930
#else
4031

0 commit comments

Comments
 (0)