Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: merge bitcoin#24460, #27672, #27766, #28065, #30228, partial bitcoin#28349, #28579 (drop c++17 support) #6380

Merged
merged 13 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ jobs:
container-path: ${{ needs.container.outputs.path }}
depends-key: ${{ needs.depends-linux64.outputs.key }}

src-linux64_cxx20:
name: linux64_cxx20-build
uses: ./.github/workflows/build-src.yml
needs: [container, depends-linux64]
with:
build-target: linux64_cxx20
container-path: ${{ needs.container.outputs.path }}
depends-key: ${{ needs.depends-linux64.outputs.key }}

src-linux64_fuzz:
name: linux64_fuzz-build
uses: ./.github/workflows/build-src.yml
Expand Down
9 changes: 0 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,6 @@ linux64-build:
variables:
BUILD_TARGET: linux64

linux64_cxx20-build:
extends:
- .build-template
- .skip-in-fast-mode-template
needs:
- x86_64-pc-linux-gnu
variables:
BUILD_TARGET: linux64_cxx20

linux64_sqlite-build:
extends:
- .build-template
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
cmake_minimum_required(VERSION 3.7)
project(dash)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

include_directories(
src
Expand Down
71 changes: 52 additions & 19 deletions build-aux/m4/ax_cxx_compile_stdcxx.m4
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
#
# Check for baseline language coverage in the compiler for the specified
# version of the C++ standard. If necessary, add switches to CXX and
# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard),
# '14' (for the C++14 standard), '17' (for the C++17 standard) or
# '20' (for the C++20 standard)
# CXXCPP to enable support. VERSION may be '11', '14', '17', or '20' for
# the respective C++ standard version.
#
# The second argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
# -std=c++11). If neither is specified, you get whatever works, with
# preference for an extended mode.
# preference for no added switch, and then for an extended mode.
#
# The third argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline support for the specified C++ standard is
Expand All @@ -36,25 +35,24 @@
# Copyright (c) 2015 Moritz Klammler <[email protected]>
# Copyright (c) 2016, 2018 Krzesimir Nowak <[email protected]>
# Copyright (c) 2019 Enji Cooper <[email protected]>
# Copyright (c) 2020 Jason Merrill <[email protected]>
# Copyright (c) 2021 Jörn Heusipp <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 11
#serial 14

dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
dnl (serial version number 13).

dnl Modifications:
dnl Add support for C++20, with no new tests

AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
[$1], [14], [ax_cxx_compile_alternatives="14 1y"],
[$1], [17], [ax_cxx_compile_alternatives="17 1z"],
[$1], [20], [ax_cxx_compile_alternatives="20 2a"],
[$1], [20], [ax_cxx_compile_alternatives="20"],
[m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$2], [], [],
[$2], [ext], [],
Expand All @@ -67,6 +65,16 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
AC_LANG_PUSH([C++])dnl
ac_success=no

m4_if([$2], [], [dnl
AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
ax_cv_cxx_compile_cxx$1,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
[ax_cv_cxx_compile_cxx$1=yes],
[ax_cv_cxx_compile_cxx$1=no])])
if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
ac_success=yes
fi])

m4_if([$2], [noext], [], [dnl
if test x$ac_success = xno; then
for alternative in ${ax_cxx_compile_alternatives}; do
Expand Down Expand Up @@ -145,33 +153,28 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
)


dnl Test body for checking C++14 support

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
)

dnl Test body for checking C++17 support

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
)

dnl Test body for checking C++20 support

dnl Test body for checking C++20 support: R modification
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20],
#ifndef __cplusplus
#error "This is not a C++ compiler"
dnl value from 2020-01-14 draft, clang 11 has 202002L
#elif __cplusplus < 201703L
#error "This is not a C++20 compiler"
#else
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
#endif
_AX_CXX_COMPILE_STDCXX_testbody_new_in_20
)


Expand Down Expand Up @@ -272,7 +275,7 @@ namespace cxx11
}

int
test(const int c, volatile int v) // 'volatile is deprecated in C++20'
test(const int c, volatile int v)
{
static_assert(is_same<int, decltype(0)>::value == true, "");
static_assert(is_same<int, decltype(c)>::value == false, "");
Expand Down Expand Up @@ -970,3 +973,33 @@ namespace cxx17
#endif // __cplusplus < 201703L

]])


dnl Tests for new features in C++20

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[

#ifndef __cplusplus

#error "This is not a C++ compiler"

#elif __cplusplus < 202002L

#error "This is not a C++20 compiler"

#else

#include <version>

namespace cxx20
{

// As C++20 supports feature test macros in the standard, there is no
// immediate need to actually test for feature availability on the
// Autoconf side.

} // namespace cxx20

#endif // __cplusplus < 202002L

]])
2 changes: 0 additions & 2 deletions ci/dash/matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ elif [ "$BUILD_TARGET" = "linux64" ]; then
source ./ci/test/00_setup_env_native_qt5.sh
elif [ "$BUILD_TARGET" = "linux64_asan" ]; then
source ./ci/test/00_setup_env_native_asan.sh
elif [ "$BUILD_TARGET" = "linux64_cxx20" ]; then
source ./ci/test/00_setup_env_native_cxx20.sh
elif [ "$BUILD_TARGET" = "linux64_fuzz" ]; then
source ./ci/test/00_setup_env_native_fuzz.sh
elif [ "$BUILD_TARGET" = "linux64_multiprocess" ]; then
Expand Down
17 changes: 0 additions & 17 deletions ci/test/00_setup_env_native_cxx20.sh

This file was deleted.

2 changes: 1 addition & 1 deletion ci/test/00_setup_env_native_fuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export CONTAINER_NAME=ci_native_fuzz
export PACKAGES="clang llvm python3 libevent-dev bsdmainutils libboost-dev"
export DEP_OPTS="NO_UPNP=1 DEBUG=1"
export CPPFLAGS="-DDEBUG_LOCKORDER -DARENA_DEBUG"
export CXXFLAGS="-Werror -Wno-unused-command-line-argument -Wno-unused-value -Wno-deprecated-builtins"
export CXXFLAGS="-Werror -Wno-unused-command-line-argument -Wno-unused-value -Wno-deprecated-builtins -Wno-deprecated-volatile"
export PYZMQ=true
export RUN_UNIT_TESTS=false
export RUN_FUNCTIONAL_TESTS=false
Expand Down
6 changes: 5 additions & 1 deletion ci/test/04_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ if [ "$RUN_FUZZ_TESTS" = "true" ] || [ "$RUN_UNIT_TESTS" = "true" ] || [ "$RUN_U
if [ ! -d "${DIR_QA_ASSETS}" ]; then
DOCKER_EXEC git clone --depth=1 https://github.com/bitcoin-core/qa-assets "${DIR_QA_ASSETS}"
fi

(
DOCKER_EXEC cd "${DIR_QA_ASSETS}"
DOCKER_EXEC echo "Using qa-assets repo from commit ..."
DOCKER_EXEC git log -1
)
export DIR_FUZZ_IN=${DIR_QA_ASSETS}/fuzz_seed_corpus/
fi

Expand Down
14 changes: 2 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,8 @@ case $host in
;;
esac

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)
if test "$use_cxx20" = "no"; then
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
else
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
fi
dnl Require C++20 compiler (no GNU extensions)
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])

dnl Unless the user specified OBJCXX, force it to be the same as CXX. This ensures
dnl that we get the same -std flags for both.
Expand Down
2 changes: 1 addition & 1 deletion depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ LTO ?=
FALLBACK_DOWNLOAD_PATH ?= http://dash-depends-sources.s3-website-us-west-2.amazonaws.com

C_STANDARD ?= c11
CXX_STANDARD ?= c++17
CXX_STANDARD ?= c++20

BUILD = $(shell ./config.guess)
HOST ?= $(BUILD)
Expand Down
2 changes: 1 addition & 1 deletion depends/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ The following can be set when running make: `make FOO=bar`
- `SDK_PATH`: Path where SDKs can be found (used by macOS)
- `FALLBACK_DOWNLOAD_PATH`: If a source file can't be fetched, try here before giving up
- `C_STANDARD`: Set the C standard version used. Defaults to `c11`.
- `CXX_STANDARD`: Set the C++ standard version used. Defaults to `c++17`.
- `CXX_STANDARD`: Set the C++ standard version used. Defaults to `c++20`.
- `NO_QT`: Don't download/build/cache Qt and its dependencies
- `NO_QR`: Don't download/build/cache packages needed for enabling qrencode
- `NO_ZMQ`: Don't download/build/cache packages needed for enabling ZeroMQ
Expand Down
2 changes: 1 addition & 1 deletion depends/packages/qt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(package)_config_opts_release += -silent
$(package)_config_opts_debug = -debug
$(package)_config_opts_debug += -optimized-tools
$(package)_config_opts += -bindir $(build_prefix)/bin
$(package)_config_opts += -c++std c++17
$(package)_config_opts += -c++std c++2a
$(package)_config_opts += -confirm-license
$(package)_config_opts += -hostprefix $(build_prefix)
$(package)_config_opts += -no-compile-examples
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
peer.is_outbound ? "out" : "in",
ConnectionTypeForNetinfo(peer.conn_type),
peer.network,
peer.transport_protocol_type.rfind('v', 0) == 0 ? peer.transport_protocol_type[1] : ' ',
peer.transport_protocol_type.starts_with('v') == 0 ? peer.transport_protocol_type[1] : ' ',
PingTimeToString(peer.min_ping),
PingTimeToString(peer.ping),
peer.last_send ? ToString(time_now - peer.last_send) : "",
Expand Down
14 changes: 0 additions & 14 deletions src/compat/assumptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@
#include <cstddef>
#include <limits>

// Assumption: We assume that the macro NDEBUG is not defined.
// Example(s): We use assert(...) extensively with the assumption of it never
// being a noop at runtime.
#if defined(NDEBUG)
# error "Dash Core cannot be compiled without assertions."
#endif

// Assumption: We assume a C++17 (ISO/IEC 14882:2017) compiler (minimum requirement).
// Example(s): We assume the presence of C++17 features everywhere :-)
// ISO Standard C++17 [cpp.predefined]p1:
// "The name __cplusplus is defined to the value 201703L when compiling a C++
// translation unit."
static_assert(__cplusplus >= 201703L, "C++17 standard assumed");

// Assumption: We assume the floating-point types to fulfill the requirements of
// IEC 559 (IEEE 754) standard.
// Example(s): Floating-point division by zero in ConnectBlock, CreateTransaction
Expand Down
2 changes: 1 addition & 1 deletion src/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <tinyformat.h>

#include <cstdio>
#include <filesystem>
#include <filesystem> // IWYU pragma: export
#include <iomanip>
#include <ios>
#include <ostream>
Expand Down
13 changes: 3 additions & 10 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,16 +1119,9 @@ constexpr std::array<std::string_view, 256> V2ShortIDs() {
static_assert(std::size(V2_DASH_IDS) <= 128);

std::array<std::string_view, 256> ret{};
for (size_t idx{0}; idx < std::size(ret); idx++) {
if (idx < 128 && idx < std::size(V2_BITCOIN_IDS)) {
ret[idx] = V2_BITCOIN_IDS[idx];
} else if (idx >= 128 && idx - 128 < std::size(V2_DASH_IDS)) {
ret[idx] = V2_DASH_IDS[idx - 128];
} else {
ret[idx] = "";
}
}

std::fill(ret.begin(), ret.end(), "");
std::copy(V2_BITCOIN_IDS.begin(), V2_BITCOIN_IDS.end(), ret.begin());
std::copy(V2_DASH_IDS.begin(), V2_DASH_IDS.end(), ret.begin() + 128);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <index/txindex.h>
#include <txmempool.h>
#include <txorphanage.h>
#include <util/check.h> // For NDEBUG compile time check
#include <util/check.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <util/trace.h>
Expand Down
6 changes: 3 additions & 3 deletions src/test/fuzz/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void initialize_addrman()
return NetGroupManager(asmap);
}

FUZZ_TARGET_INIT(data_stream_addr_man, initialize_addrman)
FUZZ_TARGET(data_stream_addr_man, .init = initialize_addrman)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
CDataStream data_stream = ConsumeDataStream(fuzzed_data_provider);
Expand Down Expand Up @@ -232,7 +232,7 @@ class AddrManDeterministic : public AddrMan
}
};

FUZZ_TARGET_INIT(addrman, initialize_addrman)
FUZZ_TARGET(addrman, .init = initialize_addrman)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
SetMockTime(ConsumeTime(fuzzed_data_provider));
Expand Down Expand Up @@ -313,7 +313,7 @@ FUZZ_TARGET_INIT(addrman, initialize_addrman)
}

// Check that serialize followed by unserialize produces the same addrman.
FUZZ_TARGET_INIT(addrman_serdeser, initialize_addrman)
FUZZ_TARGET(addrman_serdeser, .init = initialize_addrman)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
SetMockTime(ConsumeTime(fuzzed_data_provider));
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static bool operator==(const CBanEntry& lhs, const CBanEntry& rhs)
lhs.nBanUntil == rhs.nBanUntil;
}

FUZZ_TARGET_INIT(banman, initialize_banman)
FUZZ_TARGET(banman, .init = initialize_banman)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
SetMockTime(ConsumeTime(fuzzed_data_provider));
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/bip324.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void initialize_bip324()
SelectParams(CBaseChainParams::MAIN);
}

FUZZ_TARGET_INIT(bip324_cipher_roundtrip, initialize_bip324)
FUZZ_TARGET(bip324_cipher_roundtrip, .init = initialize_bip324)
{
// Test that BIP324Cipher's encryption and decryption agree.

Expand Down
Loading
Loading