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

Reduce usage of auto in line with new recommendation #9

Open
wants to merge 17 commits into
base: 2018-01-auto-devnotes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Provide explicit types for various auto vars
  • Loading branch information
ajtowns committed Jan 11, 2018
commit 03ce2380fc27caa41ac8dd0c799cad4f58d6dfd4
4 changes: 2 additions & 2 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ static const int CONTINUE_EXECUTION=-1;

std::string HelpMessageCli()
{
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
const std::unique_ptr<CBaseChainParams> defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const std::unique_ptr<CBaseChainParams> testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
std::string strUsage;
strUsage += HelpMessageGroup(_("Options:"));
strUsage += HelpMessageOpt("-?", _("This help message"));
Expand Down
2 changes: 1 addition & 1 deletion src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
struct evbuffer* evb = evhttp_request_get_output_buffer(req);
assert(evb);
evbuffer_add(evb, strReply.data(), strReply.size());
auto req_copy = req;
struct evhttp_request* req_copy = req;
HTTPEvent* ev = new HTTPEvent(eventBase, true, [req_copy, nStatus]{
evhttp_send_reply(req_copy, nStatus, nullptr, nullptr);
// Re-enable reading from the socket. This is the second part of the libevent
Expand Down
10 changes: 5 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ void OnRPCStopped()

std::string HelpMessage(HelpMessageMode mode)
{
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);
const std::unique_ptr<CBaseChainParams> defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const std::unique_ptr<CBaseChainParams> testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
const std::unique_ptr<CChainParams> defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
const std::unique_ptr<CChainParams> testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);
const bool showDebug = gArgs.GetBoolArg("-help-debug", false);

// When adding new options to the categories, please keep and ensure alphabetical ordering.
Expand Down Expand Up @@ -1708,7 +1708,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
// Initiate outbound connections unless connect=0
connOptions.m_use_addrman_outgoing = !gArgs.IsArgSet("-connect");
if (!connOptions.m_use_addrman_outgoing) {
const auto connect = gArgs.GetArgs("-connect");
const std::vector<std::string> connect = gArgs.GetArgs("-connect");
if (connect.size() != 1 || connect[0] != "0") {
connOptions.m_specified_outgoing = connect;
}
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ size_t CConnman::SocketSendData(CNode *pnode) const
size_t nSentSize = 0;

while (it != pnode->vSendMsg.end()) {
const auto &data = *it;
const std::vector<unsigned char>& data = *it;
assert(data.size() > pnode->nSendOffset);
int nBytes = 0;
{
Expand Down
6 changes: 3 additions & 3 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
push = true;
} else if (pfrom->timeLastMempoolReq) {
auto txinfo = mempool.info(inv.hash);
TxMempoolInfo txinfo = mempool.info(inv.hash);
// To protect privacy, do not answer getdata using the mempool when
// that TX couldn't have been INVed in reply to a MEMPOOL request.
if (txinfo.tx && txinfo.nTime <= pfrom->timeLastMempoolReq) {
Expand Down Expand Up @@ -3447,7 +3447,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM

// Respond to BIP35 mempool requests
if (fSendTrickle && pto->fSendMempool) {
auto vtxinfo = mempool.infoAll();
std::vector<TxMempoolInfo> vtxinfo = mempool.infoAll();
pto->fSendMempool = false;
CAmount filterrate = 0;
{
Expand Down Expand Up @@ -3512,7 +3512,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
continue;
}
// Not in the mempool anymore? don't bother sending it.
auto txinfo = mempool.info(hash);
TxMempoolInfo txinfo = mempool.info(hash);
if (!txinfo.tx) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/askpassphrasedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ bool AskPassphraseDialog::event(QEvent *event)
void AskPassphraseDialog::toggleShowPassword(bool show)
{
ui->toggleShowPasswordButton->setDown(show);
const auto mode = show ? QLineEdit::Normal : QLineEdit::Password;
const QLineEdit::EchoMode mode = show ? QLineEdit::Normal : QLineEdit::Password;
ui->passEdit1->setEchoMode(mode);
ui->passEdit2->setEchoMode(mode);
ui->passEdit3->setEchoMode(mode);
Expand Down
8 changes: 4 additions & 4 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
}
break;
case ProxyIP: {
auto ip_port = GetProxySetting(settings, "addrProxy");
ProxySetting ip_port = GetProxySetting(settings, "addrProxy");
if (!ip_port.is_set || ip_port.ip != value.toString()) {
ip_port.ip = value.toString();
SetProxySetting(settings, "addrProxy", ip_port);
Expand All @@ -339,7 +339,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
}
break;
case ProxyPort: {
auto ip_port = GetProxySetting(settings, "addrProxy");
ProxySetting ip_port = GetProxySetting(settings, "addrProxy");
if (!ip_port.is_set || ip_port.port != value.toString()) {
ip_port.port = value.toString();
SetProxySetting(settings, "addrProxy", ip_port);
Expand All @@ -356,7 +356,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
}
break;
case ProxyIPTor: {
auto ip_port = GetProxySetting(settings, "addrSeparateProxyTor");
ProxySetting ip_port = GetProxySetting(settings, "addrSeparateProxyTor");
if (!ip_port.is_set || ip_port.ip != value.toString()) {
ip_port.ip = value.toString();
SetProxySetting(settings, "addrSeparateProxyTor", ip_port);
Expand All @@ -365,7 +365,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
}
break;
case ProxyPortTor: {
auto ip_port = GetProxySetting(settings, "addrSeparateProxyTor");
ProxySetting ip_port = GetProxySetting(settings, "addrSeparateProxyTor");
if (!ip_port.is_set || ip_port.port != value.toString()) {
ip_port.port = value.toString();
SetProxySetting(settings, "addrSeparateProxyTor", ip_port);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
SendCoinsRecipient r;
if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty())
{
auto tempChainParams = CreateChainParams(CBaseChainParams::MAIN);
std::unique_ptr<CChainParams> tempChainParams = CreateChainParams(CBaseChainParams::MAIN);

if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
SelectParams(CBaseChainParams::MAIN);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ bool WalletModel::isSpent(const COutPoint& outpoint) const
void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const
{
for (auto& group : wallet->ListCoins()) {
auto& resultGroup = mapCoins[QString::fromStdString(EncodeDestination(group.first))];
std::vector<COutput>& resultGroup = mapCoins[QString::fromStdString(EncodeDestination(group.first))];
for (auto& coin : group.second) {
resultGroup.emplace_back(std::move(coin));
}
Expand Down
4 changes: 2 additions & 2 deletions src/support/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ MAKE_RAII(evhttp_request);
MAKE_RAII(evhttp_connection);

inline raii_event_base obtain_event_base() {
auto result = raii_event_base(event_base_new());
raii_event_base result{event_base_new()};
if (!result.get())
throw std::runtime_error("cannot create event_base");
return result;
Expand All @@ -47,7 +47,7 @@ inline raii_evhttp_request obtain_evhttp_request(void(*cb)(struct evhttp_request
}

inline raii_evhttp_connection obtain_evhttp_connection_base(struct event_base* base, std::string host, uint16_t port) {
auto result = raii_evhttp_connection(evhttp_connection_base_new(base, nullptr, host.c_str(), port));
raii_evhttp_connection result{evhttp_connection_base_new(base, nullptr, host.c_str(), port)};
if (!result.get())
throw std::runtime_error("create connection failed");
return result;
Expand Down
4 changes: 2 additions & 2 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ std::vector<CTxMemPool::indexed_transaction_set::const_iterator> CTxMemPool::Get
void CTxMemPool::queryHashes(std::vector<uint256>& vtxid)
{
LOCK(cs);
auto iters = GetSortedDepthAndScore();
std::vector<indexed_transaction_set::const_iterator> iters = GetSortedDepthAndScore();

vtxid.clear();
vtxid.reserve(mapTx.size());
Expand All @@ -803,7 +803,7 @@ static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator
std::vector<TxMempoolInfo> CTxMemPool::infoAll() const
{
LOCK(cs);
auto iters = GetSortedDepthAndScore();
std::vector<indexed_transaction_set::const_iterator> iters = GetSortedDepthAndScore();

std::vector<TxMempoolInfo> ret;
ret.reserve(mapTx.size());
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
}
auto keyid = GetKeyForDestination(*pwallet, dest);
CKeyID keyid = GetKeyForDestination(*pwallet, dest);
if (keyid.IsNull()) {
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
}
Expand Down