From 683be4086efeb0858c3739839c2a190c4e939b61 Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Sat, 11 Dec 2021 17:14:17 -0500 Subject: [PATCH] build: enable experimental Cxx20 support (#4600) * build: Add optional c++20 compilation option * build: update ax_cxx_compile_stdcxx.m4 to be compatible with c++20 * fix: fix c++20 build error for undefined identifier * ci: enable c++20 build during ci * cxx17 -> cxx20 Signed-off-by: pasta --- .gitlab-ci.yml | 4 ++-- build-aux/m4/ax_cxx_compile_stdcxx.m4 | 27 ++++++++++++++++++++++++--- ci/matrix.sh | 4 ++-- configure.ac | 14 ++++++++++++-- src/leveldb/util/env_posix.cc | 4 ++-- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 505b06fca0..a46333cd17 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -241,12 +241,12 @@ linux64-build: variables: BUILD_TARGET: linux64 -linux64_cxx17-build: +linux64_cxx20-build: extends: .build-template needs: - x86_64-unknown-linux-gnu-debug variables: - BUILD_TARGET: linux64_cxx17 + BUILD_TARGET: linux64_cxx20 linux64_nowallet-build: extends: diff --git a/build-aux/m4/ax_cxx_compile_stdcxx.m4 b/build-aux/m4/ax_cxx_compile_stdcxx.m4 index 43087b2e68..e0fb05a0e4 100644 --- a/build-aux/m4/ax_cxx_compile_stdcxx.m4 +++ b/build-aux/m4/ax_cxx_compile_stdcxx.m4 @@ -10,8 +10,9 @@ # # 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) -# or '14' (for the C++14 standard). +# 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) # # 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. @@ -46,10 +47,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"], [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl m4_if([$2], [], [], [$2], [ext], [], @@ -154,6 +159,22 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17], _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 ) + +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 +) + + dnl Tests for new features in C++11 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ @@ -251,7 +272,7 @@ namespace cxx11 } int - test(const int c, volatile int v) + test(const int c, volatile int v) // 'volatile is deprecated in C++20' { static_assert(is_same::value == true, ""); static_assert(is_same::value == false, ""); diff --git a/ci/matrix.sh b/ci/matrix.sh index c40c88d51f..ca6c8c9b36 100755 --- a/ci/matrix.sh +++ b/ci/matrix.sh @@ -59,10 +59,10 @@ elif [ "$BUILD_TARGET" = "linux64" ]; then export BITCOIN_CONFIG="--enable-zmq --enable-reduce-exports --enable-crash-hooks --with-sanitizers=undefined" export CPPFLAGS="-DDEBUG_LOCKORDER -DENABLE_DASH_DEBUG -DARENA_DEBUG" export PYZMQ=true -elif [ "$BUILD_TARGET" = "linux64_cxx17" ]; then +elif [ "$BUILD_TARGET" = "linux64_cxx20" ]; then export HOST=x86_64-unknown-linux-gnu export DEP_OPTS="NO_UPNP=1 DEBUG=1" - export BITCOIN_CONFIG="--enable-zmq --enable-reduce-exports --enable-crash-hooks --enable-c++17 --enable-suppress-external-warnings --enable-werror --with-sanitizers=undefined" + export BITCOIN_CONFIG="--enable-zmq --enable-reduce-exports --enable-crash-hooks --enable-c++20 --enable-suppress-external-warnings --enable-werror --with-sanitizers=undefined" export CPPFLAGS="-DDEBUG_LOCKORDER -DENABLE_DASH_DEBUG -DARENA_DEBUG" export PYZMQ=true export RUN_INTEGRATIONTESTS=false diff --git a/configure.ac b/configure.ac index abaaa65aa1..6b4cba8fe2 100644 --- a/configure.ac +++ b/configure.ac @@ -62,8 +62,18 @@ case $host in ;; esac -dnl Require C++17 compiler (no GNU extensions) -AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory]) +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 or C++20 compiler (no GNU extensions) +if test "x$use_cxx20" = xyes; then + AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory]) +else + AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory]) +fi dnl Check if -latomic is required for CHECK_ATOMIC diff --git a/src/leveldb/util/env_posix.cc b/src/leveldb/util/env_posix.cc index 9f5863a0f3..18626b327c 100644 --- a/src/leveldb/util/env_posix.cc +++ b/src/leveldb/util/env_posix.cc @@ -850,7 +850,7 @@ class SingletonEnv { public: SingletonEnv() { #if !defined(NDEBUG) - env_initialized_.store(true, std::memory_order::memory_order_relaxed); + env_initialized_.store(true, std::memory_order_relaxed); #endif // !defined(NDEBUG) static_assert(sizeof(env_storage_) >= sizeof(EnvType), "env_storage_ will not fit the Env"); @@ -867,7 +867,7 @@ class SingletonEnv { static void AssertEnvNotInitialized() { #if !defined(NDEBUG) - assert(!env_initialized_.load(std::memory_order::memory_order_relaxed)); + assert(!env_initialized_.load(std::memory_order_relaxed)); #endif // !defined(NDEBUG) }