Skip to content

Commit

Permalink
Remove 'boost::optional'-related gcc warnings
Browse files Browse the repository at this point in the history
Summary: Backport of core [[bitcoin/bitcoin#15292 | PR15292]].

Test Plan:
With GCC:
  ninja check
Make sure the warnings are gone (tested with GCC 7.5).

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D5696
  • Loading branch information
hebasto authored and Fabcien committed Apr 11, 2020
1 parent 4dcb27a commit 816f2c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
#ifndef BITCOIN_OPTIONAL_H
#define BITCOIN_OPTIONAL_H

#include <utility>

#include <boost/optional.hpp>

//! Substitute for C++17 std::optional
template <typename T> using Optional = boost::optional<T>;

//! Substitute for C++17 std::make_optional
template <typename T> Optional<T> MakeOptional(bool condition, T &&value) {
return boost::make_optional(condition, std::forward<T>(value));
}

//! Substitute for C++17 std::nullopt
static auto &nullopt = boost::none;

Expand Down
8 changes: 5 additions & 3 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,9 +1939,11 @@ static UniValue listsinceblock(const Config &config,
auto locked_chain = pwallet->chain().lock();
LOCK(pwallet->cs_wallet);

// Height of the specified block or the common ancestor, if the block
// provided was in a deactivated chain.
Optional<int> height;
// The way the 'height' is initialized is just a workaround for the gcc bug
// #47679 since version 4.6.0. Height of the specified block or the common
// ancestor, if the block provided was in a deactivated chain.
Optional<int> height = MakeOptional(false, int());

// Height of the specified block, even if it's in a deactivated chain.
Optional<int> altheight;
int target_confirms = 1;
Expand Down
4 changes: 3 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,9 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()),
0);
BlockHash tip_hash;
Optional<int> block_height;
// The way the 'block_height' is initialized is just a workaround for
// the gcc bug #47679 since version 4.6.0.
Optional<int> block_height = MakeOptional(false, int());
double progress_begin;
double progress_end;
{
Expand Down

0 comments on commit 816f2c7

Please sign in to comment.