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

build, refactor: bump to C++17 #2113

Merged
merged 13 commits into from
May 1, 2021
455 changes: 419 additions & 36 deletions build-aux/m4/ax_cxx_compile_stdcxx.m4

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ci/test/00_setup_env_native_old.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export LC_ALL=C.UTF-8

export CONTAINER_NAME=ci_native_old
export DOCKER_NAME_TAG=ubuntu:16.04
export DOCKER_NAME_TAG=ubuntu:18.04
export PACKAGES="libqt5gui5 libqt5core5a qtbase5-dev libqt5dbus5 qttools5-dev qttools5-dev-tools libssl-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-iostreams-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev libdb5.3++-dev libminiupnpc-dev libqrencode-dev libzip-dev zlib1g zlib1g-dev libcurl4-openssl-dev"
export RUN_UNIT_TESTS=true
# export RUN_FUNCTIONAL_TESTS=false
Expand Down
5 changes: 3 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ case $host in
lt_cv_deplibs_check_method="pass_all"
;;
esac
dnl Require C++11 compiler (no GNU extensions)
AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])

dnl Require C++17 compiler (no GNU extensions)
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory], [nodefault])
dnl Check if -latomic is required for <std::atomic>
CHECK_ATOMIC

Expand Down
2 changes: 1 addition & 1 deletion depends/packages/bdb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define $(package)_set_vars
$(package)_config_opts+=--libdir=$($($(package)_type)_prefix)/lib
$(package)_config_opts_mingw32=--enable-mingw
$(package)_config_opts_linux=--with-pic
$(package)_cxxflags=-std=c++11
$(package)_cxxflags=-std=c++17
$(package)_cxxflags_aarch64_linux = $(GCCFLAGS)
$(package)_cflags_aarch64_linux = $(GCCFLAGS)
$(package)_cxxflags_arm_linux = $(GCCFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion depends/packages/bdb53.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define $(package)_set_vars
$(package)_config_opts+=--libdir=$($($(package)_type)_prefix)/lib
$(package)_config_opts_mingw32=--enable-mingw
$(package)_config_opts_linux=--with-pic
$(package)_cxxflags=-std=c++11
$(package)_cxxflags=-std=c++17
$(package)_cxxflags_aarch64_linux = $(GCCFLAGS)
$(package)_cflags_aarch64_linux = $(GCCFLAGS)
$(package)_cxxflags_arm_linux = $(GCCFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion depends/packages/boost.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ifneq (,$(findstring clang,$($(package)_cxx)))
endif
$(package)_archiver_$(host_os)=$($(package)_ar)
$(package)_config_libraries=chrono,filesystem,program_options,system,thread,test,iostreams
$(package)_cxxflags=-std=c++11 -fvisibility=hidden
$(package)_cxxflags=-std=c++17 -fvisibility=hidden
$(package)_cxxflags_linux=-fPIC
$(package)_cxxflags_android=-fPIC
endef
Expand Down
2 changes: 1 addition & 1 deletion depends/packages/qt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ define $(package)_set_vars
$(package)_config_opts_release = -release
$(package)_config_opts_debug = -debug
$(package)_config_opts += -bindir $(build_prefix)/bin
$(package)_config_opts += -c++std c++11
$(package)_config_opts += -c++std c++1z
$(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/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ GRIDCOIN_CORE_H = \
chainparamsbase.h \
checkpoints.h \
compat.h \
compat/assumptions.h \
compat/byteswap.h \
compat/endian.h \
consensus/consensus.h \
Expand Down Expand Up @@ -168,7 +169,6 @@ GRIDCOIN_CORE_H = \
txdb-leveldb.h \
ui_interface.h \
uint256.h \
util/memory.h \
util/reverse_iterator.h \
util/strencodings.h \
util/threadnames.h \
Expand Down
17 changes: 7 additions & 10 deletions src/attributes.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2009-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_ATTRIBUTES_H
#define BITCOIN_ATTRIBUTES_H

#if defined(__has_cpp_attribute)
# if __has_cpp_attribute(nodiscard)
# define NODISCARD [[nodiscard]]
# endif
#endif
#ifndef NODISCARD
# if defined(_MSC_VER) && _MSC_VER >= 1700
# define NODISCARD _Check_return_
#if defined(__clang__)
# if __has_attribute(lifetimebound)
# define LIFETIMEBOUND [[clang::lifetimebound]]
# else
# define NODISCARD __attribute__((warn_unused_result))
# define LIFETIMEBOUND
# endif
#else
# define LIFETIMEBOUND
#endif

#endif // BITCOIN_ATTRIBUTES_H
10 changes: 6 additions & 4 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#ifndef BITCOIN_BASE58_H
#define BITCOIN_BASE58_H

#include <string>
#include <vector>
#include "bignum.h"
#include "key.h"
#include "script.h"

#include <string>
#include <variant>
#include <vector>

static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

// Encode a byte sequence as a base58-encoded string
Expand Down Expand Up @@ -260,7 +262,7 @@ class CBase58Data
* The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.
*/
class CBitcoinAddress;
class CBitcoinAddressVisitor : public boost::static_visitor<bool>
class CBitcoinAddressVisitor
{
private:
CBitcoinAddress *addr;
Expand Down Expand Up @@ -295,7 +297,7 @@ class CBitcoinAddress : public CBase58Data

bool Set(const CTxDestination &dest)
{
return boost::apply_visitor(CBitcoinAddressVisitor(this), dest);
return std::visit(CBitcoinAddressVisitor(this), dest);
}

bool IsValid() const
Expand Down
4 changes: 2 additions & 2 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const CBaseChainParams& BaseParams()
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
{
if (chain == CBaseChainParams::MAIN)
return MakeUnique<CBaseChainParams>("", 32749);
return std::make_unique<CBaseChainParams>("", 32749);
else if (chain == CBaseChainParams::TESTNET)
return MakeUnique<CBaseChainParams>("testnet", 32748);
return std::make_unique<CBaseChainParams>("testnet", 32748);
else
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
Expand Down
1 change: 0 additions & 1 deletion src/chainparamsbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#pragma once

#include "util/memory.h"

#include <memory>
#include <string>
Expand Down
62 changes: 62 additions & 0 deletions src/compat/assumptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

// Compile-time verification of assumptions we make.

#ifndef BITCOIN_COMPAT_ASSUMPTIONS_H
#define BITCOIN_COMPAT_ASSUMPTIONS_H

#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 "Bitcoin 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
// and EstimateMedianVal.
static_assert(std::numeric_limits<float>::is_iec559, "IEEE 754 float assumed");
static_assert(std::numeric_limits<double>::is_iec559, "IEEE 754 double assumed");

// Assumption: We assume eight bits per byte (obviously, but remember: don't
// trust -- verify!).
// Example(s): Everywhere :-)
static_assert(std::numeric_limits<unsigned char>::digits == 8, "8-bit byte assumed");

// Assumption: We assume floating-point widths.
// Example(s): Type punning in serialization code (ser_{float,double}_to_uint{32,64}).
static_assert(sizeof(float) == 4, "32-bit float assumed");
static_assert(sizeof(double) == 8, "64-bit double assumed");

// Assumption: We assume integer widths.
// Example(s): GetSizeOfCompactSize and WriteCompactSize in the serialization
// code.
static_assert(sizeof(short) == 2, "16-bit short assumed");
static_assert(sizeof(int) == 4, "32-bit int assumed");
static_assert(sizeof(unsigned) == 4, "32-bit unsigned assumed");

// Assumption: We assume size_t to be 32-bit or 64-bit.
// Example(s): size_t assumed to be at least 32-bit in ecdsa_signature_parse_der_lax(...).
// size_t assumed to be 32-bit or 64-bit in MallocUsage(...).
static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t assumed to be 32-bit or 64-bit");
static_assert(sizeof(size_t) == sizeof(void*), "Sizes of size_t and void* assumed to be equal");

// Some important things we are NOT assuming (non-exhaustive list):
// * We are NOT assuming a specific value for std::endian::native.
// * We are NOT assuming a specific value for std::locale("").name().
// * We are NOT assuming a specific value for std::numeric_limits<char>::is_signed.

#endif // BITCOIN_COMPAT_ASSUMPTIONS_H
8 changes: 4 additions & 4 deletions src/gridcoin/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma once

#include "amount.h"
#include <boost/optional.hpp>
#include <optional>
#include <unordered_map>

class CBlockIndex;
Expand All @@ -24,7 +24,7 @@ typedef std::unordered_map<Cpid, ResearchAccount> ResearchAccountMap;
//! \brief An optional type that contains a pointer to a block index object or
//! does not.
//!
typedef boost::optional<const CBlockIndex*> BlockPtrOption;
typedef std::optional<const CBlockIndex*> BlockPtrOption;

//!
//! \brief Stores the research reward context for a CPID used to calculate
Expand Down Expand Up @@ -105,7 +105,7 @@ class ResearchAccount
BlockPtrOption FirstRewardBlock() const
{
if (m_first_block_ptr == nullptr) {
return boost::none;
return std::nullopt;
}

return BlockPtrOption(m_first_block_ptr);
Expand Down Expand Up @@ -168,7 +168,7 @@ class ResearchAccount
BlockPtrOption LastRewardBlock() const
{
if (m_last_block_ptr == nullptr) {
return boost::none;
return std::nullopt;
}

return BlockPtrOption(m_last_block_ptr);
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/claim.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "serialize.h"
#include "uint256.h"

#include <boost/optional.hpp>
#include <optional>

class CPubKey;

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/contract/contract.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "gridcoin/support/enumbytes.h"
#include "serialize.h"

#include <boost/optional.hpp>
#include <optional>
#include <string>
#include <vector>

Expand Down
5 changes: 2 additions & 3 deletions src/gridcoin/cpid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "util.h"

#include <algorithm>
#include <boost/variant/apply_visitor.hpp>
#include <openssl/md5.h>

using namespace GRC;
Expand All @@ -15,7 +14,7 @@ namespace {
//!
//! \brief Gets the string representation of a mining ID object.
//!
struct MiningIdToStringVisitor : boost::static_visitor<std::string>
struct MiningIdToStringVisitor
{
//!
//! \brief Call the mining ID variant type's \c ToString() method directly.
Expand Down Expand Up @@ -117,7 +116,7 @@ MiningId MiningId::Parse(const std::string& input)

std::string MiningId::ToString() const
{
return boost::apply_visitor(MiningIdToStringVisitor(), m_variant);
return std::visit(MiningIdToStringVisitor(), m_variant);
}

// -----------------------------------------------------------------------------
Expand Down
25 changes: 12 additions & 13 deletions src/gridcoin/cpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
#include "serialize.h"

#include <array>
#include <boost/optional.hpp>
#include <boost/variant/get.hpp>
#include <boost/variant/variant.hpp>
#include <optional>
#include <string>
#include <vector>
#include <variant>

namespace GRC {
//!
Expand Down Expand Up @@ -209,7 +208,7 @@ class Cpid
//! \brief An optional type that either contains a reference to some external
//! CPID value or does not.
//!
typedef boost::optional<const Cpid> CpidOption;
typedef std::optional<const Cpid> CpidOption;

//!
//! \brief A variant type that identifies an entity that may receive rewards.
Expand Down Expand Up @@ -299,12 +298,12 @@ class MiningId
//!
bool operator==(const MiningId& other) const
{
if (m_variant.which() != other.m_variant.which()) {
if (m_variant.index() != other.m_variant.index()) {
return false;
}

if (Which() == Kind::CPID) {
return *this == boost::get<Cpid>(other.m_variant);
return *this == std::get<Cpid>(other.m_variant);
}

return true;
Expand Down Expand Up @@ -333,7 +332,7 @@ class MiningId
bool operator==(const Cpid& other) const
{
return Which() == Kind::CPID
&& boost::get<Cpid>(m_variant) == other;
&& std::get<Cpid>(m_variant) == other;
}

//!
Expand All @@ -356,7 +355,7 @@ class MiningId
//!
Kind Which() const
{
return static_cast<Kind>(m_variant.which());
return static_cast<Kind>(m_variant.index());
}

//!
Expand All @@ -378,10 +377,10 @@ class MiningId
CpidOption TryCpid() const
{
if (Which() != Kind::CPID) {
return boost::none;
return std::nullopt;
}

return boost::get<Cpid>(m_variant);
return std::get<Cpid>(m_variant);
}

//!
Expand All @@ -400,12 +399,12 @@ class MiningId
template<typename Stream>
void Serialize(Stream& stream) const
{
unsigned char kind = m_variant.which();
unsigned char kind = m_variant.index();

::Serialize(stream, kind);

if (static_cast<Kind>(kind) == Kind::CPID) {
boost::get<Cpid>(m_variant).Serialize(stream);
std::get<Cpid>(m_variant).Serialize(stream);
}
}

Expand Down Expand Up @@ -443,7 +442,7 @@ class MiningId
//!
//! \brief Stores the various states that a mining ID may exist in.
//!
boost::variant<Invalid, Investor, Cpid> m_variant;
std::variant<Invalid, Investor, Cpid> m_variant;
}; // MiningId
} // namespace GRC

Expand Down
Loading