Skip to content

Commit cc44a68

Browse files
authored
Merge pull request #2113 from div72/c++17
build, refactor: bump to C++17
2 parents 2d8f583 + e8dfebc commit cc44a68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+708
-311
lines changed

build-aux/m4/ax_cxx_compile_stdcxx.m4

+419-36
Large diffs are not rendered by default.

ci/test/00_setup_env_native_old.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
export LC_ALL=C.UTF-8
88

99
export CONTAINER_NAME=ci_native_old
10-
export DOCKER_NAME_TAG=ubuntu:16.04
10+
export DOCKER_NAME_TAG=ubuntu:18.04
1111
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"
1212
export RUN_UNIT_TESTS=true
1313
# export RUN_FUNCTIONAL_TESTS=false

configure.ac

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ case $host in
5959
lt_cv_deplibs_check_method="pass_all"
6060
;;
6161
esac
62-
dnl Require C++11 compiler (no GNU extensions)
63-
AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])
62+
63+
dnl Require C++17 compiler (no GNU extensions)
64+
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory], [nodefault])
6465
dnl Check if -latomic is required for <std::atomic>
6566
CHECK_ATOMIC
6667

depends/packages/bdb.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define $(package)_set_vars
1111
$(package)_config_opts+=--libdir=$($($(package)_type)_prefix)/lib
1212
$(package)_config_opts_mingw32=--enable-mingw
1313
$(package)_config_opts_linux=--with-pic
14-
$(package)_cxxflags=-std=c++11
14+
$(package)_cxxflags=-std=c++17
1515
$(package)_cxxflags_aarch64_linux = $(GCCFLAGS)
1616
$(package)_cflags_aarch64_linux = $(GCCFLAGS)
1717
$(package)_cxxflags_arm_linux = $(GCCFLAGS)

depends/packages/bdb53.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define $(package)_set_vars
1111
$(package)_config_opts+=--libdir=$($($(package)_type)_prefix)/lib
1212
$(package)_config_opts_mingw32=--enable-mingw
1313
$(package)_config_opts_linux=--with-pic
14-
$(package)_cxxflags=-std=c++11
14+
$(package)_cxxflags=-std=c++17
1515
$(package)_cxxflags_aarch64_linux = $(GCCFLAGS)
1616
$(package)_cflags_aarch64_linux = $(GCCFLAGS)
1717
$(package)_cxxflags_arm_linux = $(GCCFLAGS)

depends/packages/boost.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ifneq (,$(findstring clang,$($(package)_cxx)))
2828
endif
2929
$(package)_archiver_$(host_os)=$($(package)_ar)
3030
$(package)_config_libraries=chrono,filesystem,program_options,system,thread,test,iostreams
31-
$(package)_cxxflags=-std=c++11 -fvisibility=hidden
31+
$(package)_cxxflags=-std=c++17 -fvisibility=hidden
3232
$(package)_cxxflags_linux=-fPIC
3333
$(package)_cxxflags_android=-fPIC
3434
endef

depends/packages/qt.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ define $(package)_set_vars
3636
$(package)_config_opts_release = -release
3737
$(package)_config_opts_debug = -debug
3838
$(package)_config_opts += -bindir $(build_prefix)/bin
39-
$(package)_config_opts += -c++std c++11
39+
$(package)_config_opts += -c++std c++1z
4040
$(package)_config_opts += -confirm-license
4141
$(package)_config_opts += -hostprefix $(build_prefix)
4242
$(package)_config_opts += -no-compile-examples

src/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ GRIDCOIN_CORE_H = \
7070
chainparamsbase.h \
7171
checkpoints.h \
7272
compat.h \
73+
compat/assumptions.h \
7374
compat/byteswap.h \
7475
compat/endian.h \
7576
consensus/consensus.h \
@@ -168,7 +169,6 @@ GRIDCOIN_CORE_H = \
168169
txdb-leveldb.h \
169170
ui_interface.h \
170171
uint256.h \
171-
util/memory.h \
172172
util/reverse_iterator.h \
173173
util/strencodings.h \
174174
util/threadnames.h \

src/attributes.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2018 The Bitcoin Core developers
2+
// Copyright (c) 2009-2020 The Bitcoin Core developers
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#ifndef BITCOIN_ATTRIBUTES_H
77
#define BITCOIN_ATTRIBUTES_H
88

9-
#if defined(__has_cpp_attribute)
10-
# if __has_cpp_attribute(nodiscard)
11-
# define NODISCARD [[nodiscard]]
12-
# endif
13-
#endif
14-
#ifndef NODISCARD
15-
# if defined(_MSC_VER) && _MSC_VER >= 1700
16-
# define NODISCARD _Check_return_
9+
#if defined(__clang__)
10+
# if __has_attribute(lifetimebound)
11+
# define LIFETIMEBOUND [[clang::lifetimebound]]
1712
# else
18-
# define NODISCARD __attribute__((warn_unused_result))
13+
# define LIFETIMEBOUND
1914
# endif
15+
#else
16+
# define LIFETIMEBOUND
2017
#endif
2118

2219
#endif // BITCOIN_ATTRIBUTES_H

src/base58.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
#ifndef BITCOIN_BASE58_H
1616
#define BITCOIN_BASE58_H
1717

18-
#include <string>
19-
#include <vector>
2018
#include "bignum.h"
2119
#include "key.h"
2220
#include "script.h"
2321

22+
#include <string>
23+
#include <variant>
24+
#include <vector>
25+
2426
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
2527

2628
// Encode a byte sequence as a base58-encoded string
@@ -260,7 +262,7 @@ class CBase58Data
260262
* The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.
261263
*/
262264
class CBitcoinAddress;
263-
class CBitcoinAddressVisitor : public boost::static_visitor<bool>
265+
class CBitcoinAddressVisitor
264266
{
265267
private:
266268
CBitcoinAddress *addr;
@@ -295,7 +297,7 @@ class CBitcoinAddress : public CBase58Data
295297

296298
bool Set(const CTxDestination &dest)
297299
{
298-
return boost::apply_visitor(CBitcoinAddressVisitor(this), dest);
300+
return std::visit(CBitcoinAddressVisitor(this), dest);
299301
}
300302

301303
bool IsValid() const

src/chainparamsbase.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const CBaseChainParams& BaseParams()
2323
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
2424
{
2525
if (chain == CBaseChainParams::MAIN)
26-
return MakeUnique<CBaseChainParams>("", 32749);
26+
return std::make_unique<CBaseChainParams>("", 32749);
2727
else if (chain == CBaseChainParams::TESTNET)
28-
return MakeUnique<CBaseChainParams>("testnet", 32748);
28+
return std::make_unique<CBaseChainParams>("testnet", 32748);
2929
else
3030
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
3131
}

src/chainparamsbase.h

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include "util/memory.h"
87

98
#include <memory>
109
#include <string>

src/compat/assumptions.h

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2020 The Bitcoin Core developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
// Compile-time verification of assumptions we make.
7+
8+
#ifndef BITCOIN_COMPAT_ASSUMPTIONS_H
9+
#define BITCOIN_COMPAT_ASSUMPTIONS_H
10+
11+
#include <limits>
12+
13+
// Assumption: We assume that the macro NDEBUG is not defined.
14+
// Example(s): We use assert(...) extensively with the assumption of it never
15+
// being a noop at runtime.
16+
#if defined(NDEBUG)
17+
# error "Bitcoin cannot be compiled without assertions."
18+
#endif
19+
20+
// Assumption: We assume a C++17 (ISO/IEC 14882:2017) compiler (minimum requirement).
21+
// Example(s): We assume the presence of C++17 features everywhere :-)
22+
// ISO Standard C++17 [cpp.predefined]p1:
23+
// "The name __cplusplus is defined to the value 201703L when compiling a C++
24+
// translation unit."
25+
static_assert(__cplusplus >= 201703L, "C++17 standard assumed");
26+
27+
// Assumption: We assume the floating-point types to fulfill the requirements of
28+
// IEC 559 (IEEE 754) standard.
29+
// Example(s): Floating-point division by zero in ConnectBlock, CreateTransaction
30+
// and EstimateMedianVal.
31+
static_assert(std::numeric_limits<float>::is_iec559, "IEEE 754 float assumed");
32+
static_assert(std::numeric_limits<double>::is_iec559, "IEEE 754 double assumed");
33+
34+
// Assumption: We assume eight bits per byte (obviously, but remember: don't
35+
// trust -- verify!).
36+
// Example(s): Everywhere :-)
37+
static_assert(std::numeric_limits<unsigned char>::digits == 8, "8-bit byte assumed");
38+
39+
// Assumption: We assume floating-point widths.
40+
// Example(s): Type punning in serialization code (ser_{float,double}_to_uint{32,64}).
41+
static_assert(sizeof(float) == 4, "32-bit float assumed");
42+
static_assert(sizeof(double) == 8, "64-bit double assumed");
43+
44+
// Assumption: We assume integer widths.
45+
// Example(s): GetSizeOfCompactSize and WriteCompactSize in the serialization
46+
// code.
47+
static_assert(sizeof(short) == 2, "16-bit short assumed");
48+
static_assert(sizeof(int) == 4, "32-bit int assumed");
49+
static_assert(sizeof(unsigned) == 4, "32-bit unsigned assumed");
50+
51+
// Assumption: We assume size_t to be 32-bit or 64-bit.
52+
// Example(s): size_t assumed to be at least 32-bit in ecdsa_signature_parse_der_lax(...).
53+
// size_t assumed to be 32-bit or 64-bit in MallocUsage(...).
54+
static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t assumed to be 32-bit or 64-bit");
55+
static_assert(sizeof(size_t) == sizeof(void*), "Sizes of size_t and void* assumed to be equal");
56+
57+
// Some important things we are NOT assuming (non-exhaustive list):
58+
// * We are NOT assuming a specific value for std::endian::native.
59+
// * We are NOT assuming a specific value for std::locale("").name().
60+
// * We are NOT assuming a specific value for std::numeric_limits<char>::is_signed.
61+
62+
#endif // BITCOIN_COMPAT_ASSUMPTIONS_H

src/gridcoin/account.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#pragma once
66

77
#include "amount.h"
8-
#include <boost/optional.hpp>
8+
#include <optional>
99
#include <unordered_map>
1010

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

2929
//!
3030
//! \brief Stores the research reward context for a CPID used to calculate
@@ -105,7 +105,7 @@ class ResearchAccount
105105
BlockPtrOption FirstRewardBlock() const
106106
{
107107
if (m_first_block_ptr == nullptr) {
108-
return boost::none;
108+
return std::nullopt;
109109
}
110110

111111
return BlockPtrOption(m_first_block_ptr);
@@ -168,7 +168,7 @@ class ResearchAccount
168168
BlockPtrOption LastRewardBlock() const
169169
{
170170
if (m_last_block_ptr == nullptr) {
171-
return boost::none;
171+
return std::nullopt;
172172
}
173173

174174
return BlockPtrOption(m_last_block_ptr);

src/gridcoin/claim.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "serialize.h"
1212
#include "uint256.h"
1313

14-
#include <boost/optional.hpp>
14+
#include <optional>
1515

1616
class CPubKey;
1717

src/gridcoin/contract/contract.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "gridcoin/support/enumbytes.h"
1010
#include "serialize.h"
1111

12-
#include <boost/optional.hpp>
12+
#include <optional>
1313
#include <string>
1414
#include <vector>
1515

src/gridcoin/cpid.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "util.h"
77

88
#include <algorithm>
9-
#include <boost/variant/apply_visitor.hpp>
109
#include <openssl/md5.h>
1110

1211
using namespace GRC;
@@ -15,7 +14,7 @@ namespace {
1514
//!
1615
//! \brief Gets the string representation of a mining ID object.
1716
//!
18-
struct MiningIdToStringVisitor : boost::static_visitor<std::string>
17+
struct MiningIdToStringVisitor
1918
{
2019
//!
2120
//! \brief Call the mining ID variant type's \c ToString() method directly.
@@ -117,7 +116,7 @@ MiningId MiningId::Parse(const std::string& input)
117116

118117
std::string MiningId::ToString() const
119118
{
120-
return boost::apply_visitor(MiningIdToStringVisitor(), m_variant);
119+
return std::visit(MiningIdToStringVisitor(), m_variant);
121120
}
122121

123122
// -----------------------------------------------------------------------------

src/gridcoin/cpid.h

+12-13
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
#include "serialize.h"
88

99
#include <array>
10-
#include <boost/optional.hpp>
11-
#include <boost/variant/get.hpp>
12-
#include <boost/variant/variant.hpp>
10+
#include <optional>
1311
#include <string>
1412
#include <vector>
13+
#include <variant>
1514

1615
namespace GRC {
1716
//!
@@ -209,7 +208,7 @@ class Cpid
209208
//! \brief An optional type that either contains a reference to some external
210209
//! CPID value or does not.
211210
//!
212-
typedef boost::optional<const Cpid> CpidOption;
211+
typedef std::optional<const Cpid> CpidOption;
213212

214213
//!
215214
//! \brief A variant type that identifies an entity that may receive rewards.
@@ -299,12 +298,12 @@ class MiningId
299298
//!
300299
bool operator==(const MiningId& other) const
301300
{
302-
if (m_variant.which() != other.m_variant.which()) {
301+
if (m_variant.index() != other.m_variant.index()) {
303302
return false;
304303
}
305304

306305
if (Which() == Kind::CPID) {
307-
return *this == boost::get<Cpid>(other.m_variant);
306+
return *this == std::get<Cpid>(other.m_variant);
308307
}
309308

310309
return true;
@@ -333,7 +332,7 @@ class MiningId
333332
bool operator==(const Cpid& other) const
334333
{
335334
return Which() == Kind::CPID
336-
&& boost::get<Cpid>(m_variant) == other;
335+
&& std::get<Cpid>(m_variant) == other;
337336
}
338337

339338
//!
@@ -356,7 +355,7 @@ class MiningId
356355
//!
357356
Kind Which() const
358357
{
359-
return static_cast<Kind>(m_variant.which());
358+
return static_cast<Kind>(m_variant.index());
360359
}
361360

362361
//!
@@ -378,10 +377,10 @@ class MiningId
378377
CpidOption TryCpid() const
379378
{
380379
if (Which() != Kind::CPID) {
381-
return boost::none;
380+
return std::nullopt;
382381
}
383382

384-
return boost::get<Cpid>(m_variant);
383+
return std::get<Cpid>(m_variant);
385384
}
386385

387386
//!
@@ -400,12 +399,12 @@ class MiningId
400399
template<typename Stream>
401400
void Serialize(Stream& stream) const
402401
{
403-
unsigned char kind = m_variant.which();
402+
unsigned char kind = m_variant.index();
404403

405404
::Serialize(stream, kind);
406405

407406
if (static_cast<Kind>(kind) == Kind::CPID) {
408-
boost::get<Cpid>(m_variant).Serialize(stream);
407+
std::get<Cpid>(m_variant).Serialize(stream);
409408
}
410409
}
411410

@@ -443,7 +442,7 @@ class MiningId
443442
//!
444443
//! \brief Stores the various states that a mining ID may exist in.
445444
//!
446-
boost::variant<Invalid, Investor, Cpid> m_variant;
445+
std::variant<Invalid, Investor, Cpid> m_variant;
447446
}; // MiningId
448447
} // namespace GRC
449448

0 commit comments

Comments
 (0)