From 40c259bdf36e0c4aaac855a15a8df66f4439b44f Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Wed, 1 Dec 2021 14:59:34 -0500 Subject: [PATCH] fix: resolve numerous compilation warnings under -Wall (#4599) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: compilation warnings ./validation.h:266:13: warning: ‘bool AcceptToMemoryPoolWithTime(const CChainParams&, CTxMemPool&, CValidationState&, const CTransactionRef&, bool*, int64_t, bool, CAmount, bool)’ declared ‘static’ but never defined [-Wunused-function] static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, ^~~~~~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings ./coinjoin/client.h: In constructor ‘CCoinJoinClientManager::CCoinJoinClientManager(CWallet&)’: ./coinjoin/client.h:199:10: warning: ‘CCoinJoinClientManager::fCreateAutoBackups’ will be initialized after [-Wreorder] bool fCreateAutoBackups; // builtin support for automatic backups ^~~~~~~~~~~~~~~~~~ ./coinjoin/client.h:187:14: warning: ‘CWallet& CCoinJoinClientManager::mixingWallet’ [-Wreorder] CWallet& mixingWallet; ^~~~~~~~~~~~ ./coinjoin/client.h:205:14: warning: when initialized here [-Wreorder] explicit CCoinJoinClientManager(CWallet& wallet) : ^~~~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings interfaces/wallet.cpp: In constructor ‘interfaces::{anonymous}::WalletImpl::WalletImpl(const std::shared_ptr&)’: interfaces/wallet.cpp:594:30: warning: ‘interfaces::{anonymous}::WalletImpl::m_wallet’ will be initialized after [-Wreorder] std::shared_ptr m_wallet; ^~~~~~~~ interfaces/wallet.cpp:191:18: warning: ‘interfaces::{anonymous}::CoinJoinImpl interfaces::{anonymous}::WalletImpl::m_coinjoin’ [-Wreorder] CoinJoinImpl m_coinjoin; ^~~~~~~~~~ interfaces/wallet.cpp:193:14: warning: when initialized here [-Wreorder] explicit WalletImpl(const std::shared_ptr& wallet) : m_wallet(wallet), m_coinjoin(wallet) {} ^~~~~~~~~~ * fix: compilation warnings validation.cpp:165:13: warning: ‘void CheckBlockIndex(const Consensus::Params&)’ declared ‘static’ but never defined [-Wunused-function] static void CheckBlockIndex(const Consensus::Params& consensusParams); ^~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp: In constructor ‘ContributionVerifier::ContributionVerifier(CBLSId, const std::vector > >&, const BLSSecretKeyVector&, size_t, bool, bool, ctpl::thread_pool&, std::function&)>)’: bls/bls_worker.cpp:425:51: warning: ‘ContributionVerifier::doneCallback’ will be initialized after [-Wreorder] std::function&)> doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:420:12: warning: ‘size_t ContributionVerifier::batchCount’ [-Wreorder] size_t batchCount; ^~~~~~~~~~ bls/bls_worker.cpp:427:5: warning: when initialized here [-Wreorder] ContributionVerifier(CBLSId _forId, const std::vector& _vvecs, ^~~~~~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:342:10: warning: ‘VectorAggregator::parallel’ will be initialized after [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:340:12: warning: ‘size_t VectorAggregator::start’ [-Wreorder] size_t start; ^~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ bls/bls_worker.cpp:343:24: warning: ‘VectorAggregator::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:337:18: warning: ‘VectorAggregator::DoneCallback VectorAggregator::doneCallback’ [-Wreorder] DoneCallback doneCallback; ^~~~~~~~~~~~ bls/bls_worker.cpp:350:5: warning: when initialized here [-Wreorder] VectorAggregator(const VectorVectorType& _vecs, ^~~~~~~~~~~~~~~~ * fix: compilation warnings bls/bls_worker.cpp:494:235: required from here bls/bls_worker.cpp:136:24: warning: ‘Aggregator::workerPool’ will be initialized after [-Wreorder] ctpl::thread_pool& workerPool; ^~~~~~~~~~ bls/bls_worker.cpp:135:10: warning: ‘bool Aggregator::parallel’ [-Wreorder] bool parallel; ^~~~~~~~ bls/bls_worker.cpp:152:5: warning: when initialized here [-Wreorder] Aggregator(const std::vector& _inputVec, ^~~~~~~~~~ * fix: compilation warnings bench/string_cast.cpp: In lambda function: bench/string_cast.cpp:22:13: warning: statement has no effect [-Wunused-value] atoi("1"); ~~~~^~~~~ * fix: compilation warnings ./llmq/dkgsessionhandler.h: In constructor ‘llmq::CDKGPendingMessages::CDKGPendingMessages(size_t, int)’: ./llmq/dkgsessionhandler.h:48:12: warning: ‘llmq::CDKGPendingMessages::maxMessagesPerNode’ will be initialized after [-Wreorder] size_t maxMessagesPerNode GUARDED_BY(cs); ^~~~~~~~~~~~~~~~~~ ./llmq/dkgsessionhandler.h:47:15: warning: ‘const int llmq::CDKGPendingMessages::invType’ [-Wreorder] const int invType; ^~~~~~~ llmq/dkgsessionhandler.cpp:23:1: warning: when initialized here [-Wreorder] CDKGPendingMessages::CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) : ^~~~~~~~~~~~~~~~~~~ * fix: compilation warnings Not sure this one is correct, but I believe so. Seems like the `!= 0` is completely not needed rpc/masternode.cpp: In function ‘UniValue masternode_payments(const JSONRPCRequest&)’: rpc/masternode.cpp:442:31: warning: suggest parentheses around comparison in operand of ‘!=’ [-Wparentheses] while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) { ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ * fix: compilation warnings test/cachemultimap_tests.cpp:14:13: warning: ‘void cachemultimap_tests::DumpMap(const CacheMultiMap&)’ defined but not used [-Wunused-function] static void DumpMap(const CacheMultiMap& cmmap) ^~~~~~~ * fix: compilation warnings In file included from qt/appearancewidget.cpp:11: ./qt/appearancewidget.h: In constructor ‘AppearanceWidget::AppearanceWidget(QWidget*)’: ./qt/appearancewidget.h:52:25: warning: ‘AppearanceWidget::prevFontFamily’ will be initialized after [-Wreorder] GUIUtil::FontFamily prevFontFamily; ^~~~~~~~~~~~~~ ./qt/appearancewidget.h:51:9: warning: ‘int AppearanceWidget::prevScale’ [-Wreorder] int prevScale; ^~~~~~~~~ qt/appearancewidget.cpp:21:1: warning: when initialized here [-Wreorder] AppearanceWidget::AppearanceWidget(QWidget* parent) : ^~~~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/bitcoingui.cpp:6: ./qt/bitcoingui.h: In constructor ‘BitcoinGUI::BitcoinGUI(interfaces::Node&, const NetworkStyle*, QWidget*)’: ./qt/bitcoingui.h:212:31: warning: ‘BitcoinGUI::m_network_style’ will be initialized after [-Wreorder] const NetworkStyle* const m_network_style; ^~~~~~~~~~~~~~~ ./qt/bitcoingui.h:172:34: warning: ‘const std::unique_ptr BitcoinGUI::trayIconMenu’ [-Wreorder] const std::unique_ptr trayIconMenu; ^~~~~~~~~~~~ qt/bitcoingui.cpp:81:1: warning: when initialized here [-Wreorder] BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : ^~~~~~~~~~ * fix: compilation warnings In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h: In constructor ‘MasternodeList::MasternodeList(QWidget*)’: ./qt/masternodelist.h:66:18: warning: ‘MasternodeList::walletModel’ will be initialized after [-Wreorder] WalletModel* walletModel; ^~~~~~~~~~~ ./qt/masternodelist.h:61:10: warning: ‘bool MasternodeList::fFilterUpdatedDIP3’ [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ In file included from qt/masternodelist.cpp:1: ./qt/masternodelist.h:61:10: warning: ‘MasternodeList::fFilterUpdatedDIP3’ will be initialized after [-Wreorder] bool fFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~ ./qt/masternodelist.h:59:13: warning: ‘int64_t MasternodeList::nTimeFilterUpdatedDIP3’ [-Wreorder] int64_t nTimeFilterUpdatedDIP3; ^~~~~~~~~~~~~~~~~~~~~~ qt/masternodelist.cpp:45:1: warning: when initialized here [-Wreorder] MasternodeList::MasternodeList(QWidget* parent) : ^~~~~~~~~~~~~~ * fix: compilation warnings In file included from qt/paymentserver.cpp:10: ./qt/paymentserver.h: In constructor ‘PaymentServer::PaymentServer(QObject*, bool)’: ./qt/paymentserver.h:156:28: warning: ‘PaymentServer::netManager’ will be initialized after [-Wreorder] QNetworkAccessManager* netManager; // Used to fetch payment requests ^~~~~~~~~~ ./qt/paymentserver.h:147:19: warning: ‘OptionsModel* PaymentServer::optionsModel’ [-Wreorder] OptionsModel *optionsModel; ^~~~~~~~~~~~ qt/paymentserver.cpp:197:1: warning: when initialized here [-Wreorder] PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : ^~~~~~~~~~~~~ --- src/bench/string_cast.cpp | 3 ++- src/bls/bls_worker.cpp | 18 ++++++++---------- src/coinjoin/client.h | 22 ++++++---------------- src/interfaces/wallet.cpp | 2 +- src/llmq/dkgsessionhandler.cpp | 4 ++-- src/qt/appearancewidget.cpp | 8 +------- src/qt/appearancewidget.h | 12 ++++++------ src/qt/bitcoingui.cpp | 4 ++-- src/qt/masternodelist.cpp | 8 +------- src/qt/masternodelist.h | 12 ++++++------ src/qt/paymentserver.cpp | 4 ++-- src/qt/paymentserver.h | 8 ++++---- src/rpc/masternode.cpp | 2 +- src/test/cachemultimap_tests.cpp | 9 --------- src/validation.cpp | 2 -- src/validation.h | 3 --- 16 files changed, 42 insertions(+), 79 deletions(-) diff --git a/src/bench/string_cast.cpp b/src/bench/string_cast.cpp index e08356433a..655a63a598 100644 --- a/src/bench/string_cast.cpp +++ b/src/bench/string_cast.cpp @@ -18,8 +18,9 @@ std::string NumberToString(T Number){ static void int_atoi(benchmark::Bench& bench) { + int value; bench.run([&] { - atoi("1"); + value = atoi("1"); }); } diff --git a/src/bls/bls_worker.cpp b/src/bls/bls_worker.cpp index a0b73606fc..9ddaa1c7a8 100644 --- a/src/bls/bls_worker.cpp +++ b/src/bls/bls_worker.cpp @@ -154,8 +154,8 @@ struct Aggregator : public std::enable_shared_from_this> { bool _parallel, ctpl::thread_pool& _workerPool, DoneCallback _doneCallback) : - workerPool(_workerPool), parallel(_parallel), + workerPool(_workerPool), doneCallback(std::move(_doneCallback)) { inputVec = std::make_shared >(count); @@ -342,7 +342,7 @@ struct VectorAggregator : public std::enable_shared_from_this doneCount; + std::atomic doneCount{0}; VectorPtrType result; size_t vecSize; @@ -351,13 +351,12 @@ struct VectorAggregator : public std::enable_shared_from_thissize(); @@ -417,7 +416,7 @@ struct ContributionVerifier : public std::enable_shared_from_this batchStates; @@ -435,9 +434,8 @@ struct ContributionVerifier : public std::enable_shared_from_this::max()}; // used for the overview screen + bool fCreateAutoBackups{true}; // builtin support for automatic backups CCoinJoinClientManager() = delete; CCoinJoinClientManager(CCoinJoinClientManager const&) = delete; CCoinJoinClientManager& operator=(CCoinJoinClientManager const&) = delete; explicit CCoinJoinClientManager(CWallet& wallet) : - vecMasternodesUsed(), - deqSessions(), - nCachedLastSuccessBlock(0), - nMinBlocksToWait(1), - strAutoDenomResult(), - nCachedBlockHeight(0), - nCachedNumBlocks(std::numeric_limits::max()), - fCreateAutoBackups(true), - mixingWallet(wallet) - { - } + mixingWallet(wallet) {} void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61); diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 896ddf707a..bb49f9bf73 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -188,7 +188,6 @@ public: class WalletImpl : public Wallet { public: - CoinJoinImpl m_coinjoin; explicit WalletImpl(const std::shared_ptr& wallet) : m_wallet(wallet), m_coinjoin(wallet) {} @@ -592,6 +591,7 @@ public: } std::shared_ptr m_wallet; + CoinJoinImpl m_coinjoin; }; class WalletClientImpl : public ChainClient diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 82b7ea48a6..d0af4e6225 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -21,8 +21,8 @@ namespace llmq { CDKGPendingMessages::CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) : - maxMessagesPerNode(_maxMessagesPerNode), - invType(_invType) + invType(_invType), + maxMessagesPerNode(_maxMessagesPerNode) { } diff --git a/src/qt/appearancewidget.cpp b/src/qt/appearancewidget.cpp index 25d6ade491..e74e91ba1b 100644 --- a/src/qt/appearancewidget.cpp +++ b/src/qt/appearancewidget.cpp @@ -20,13 +20,7 @@ AppearanceWidget::AppearanceWidget(QWidget* parent) : QWidget(parent), - ui(new Ui::AppearanceWidget), - fAcceptChanges(false), - prevTheme(GUIUtil::getActiveTheme()), - prevFontFamily(GUIUtil::getFontFamily()), - prevScale(GUIUtil::getFontScale()), - prevWeightNormal(GUIUtil::getFontWeightNormal()), - prevWeightBold(GUIUtil::getFontWeightBold()) + ui{new Ui::AppearanceWidget()} { ui->setupUi(this); diff --git a/src/qt/appearancewidget.h b/src/qt/appearancewidget.h index 632750d472..2aea003d6f 100644 --- a/src/qt/appearancewidget.h +++ b/src/qt/appearancewidget.h @@ -46,12 +46,12 @@ private: Ui::AppearanceWidget* ui; QDataWidgetMapper* mapper; OptionsModel* model; - bool fAcceptChanges; - QString prevTheme; - int prevScale; - GUIUtil::FontFamily prevFontFamily; - QFont::Weight prevWeightNormal; - QFont::Weight prevWeightBold; + bool fAcceptChanges{false}; + QString prevTheme{GUIUtil::getActiveTheme()}; + int prevScale{GUIUtil::getFontScale()}; + GUIUtil::FontFamily prevFontFamily{GUIUtil::getFontFamily()}; + QFont::Weight prevWeightNormal{GUIUtil::getFontWeightNormal()}; + QFont::Weight prevWeightBold{GUIUtil::getFontWeightBold()}; void updateWeightSlider(bool fForce = false); }; diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index e898faedcc..14c7c86c9c 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -81,8 +81,8 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM = BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : QMainWindow(parent), m_node(node), - m_network_style(networkStyle), - trayIconMenu{new QMenu()} + trayIconMenu{new QMenu()}, + m_network_style(networkStyle) { GUIUtil::loadTheme(true); diff --git a/src/qt/masternodelist.cpp b/src/qt/masternodelist.cpp index b0cb336127..824f328fac 100644 --- a/src/qt/masternodelist.cpp +++ b/src/qt/masternodelist.cpp @@ -44,13 +44,7 @@ public: MasternodeList::MasternodeList(QWidget* parent) : QWidget(parent), - ui(new Ui::MasternodeList), - clientModel(0), - walletModel(0), - fFilterUpdatedDIP3(true), - nTimeFilterUpdatedDIP3(0), - nTimeUpdatedDIP3(0), - mnListChanged(true) + ui(new Ui::MasternodeList) { ui->setupUi(this); diff --git a/src/qt/masternodelist.h b/src/qt/masternodelist.h index 40203d2de4..acfd100742 100644 --- a/src/qt/masternodelist.h +++ b/src/qt/masternodelist.h @@ -56,21 +56,21 @@ public: private: QMenu* contextMenuDIP3; - int64_t nTimeFilterUpdatedDIP3; - int64_t nTimeUpdatedDIP3; - bool fFilterUpdatedDIP3; + int64_t nTimeFilterUpdatedDIP3{0}; + int64_t nTimeUpdatedDIP3{0}; + bool fFilterUpdatedDIP3{true}; QTimer* timer; Ui::MasternodeList* ui; - ClientModel* clientModel; - WalletModel* walletModel; + ClientModel* clientModel{nullptr}; + WalletModel* walletModel{nullptr}; // Protects tableWidgetMasternodesDIP3 CCriticalSection cs_dip3list; QString strCurrentFilterDIP3; - bool mnListChanged; + bool mnListChanged{true}; CDeterministicMNCPtr GetSelectedDIP3MN(); diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index dc9031bbbb..ac1b298a65 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -196,11 +196,11 @@ bool PaymentServer::ipcSendCommandLine() PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : QObject(parent), - saveURIs(true), - uriServer(nullptr), #ifdef ENABLE_BIP70 netManager(nullptr), #endif + saveURIs(true), + uriServer(nullptr), optionsModel(nullptr) { #ifdef ENABLE_BIP70 diff --git a/src/qt/paymentserver.h b/src/qt/paymentserver.h index cb66d15229..862d132a3d 100644 --- a/src/qt/paymentserver.h +++ b/src/qt/paymentserver.h @@ -142,10 +142,6 @@ protected: bool eventFilter(QObject *object, QEvent *event) override; private: - bool saveURIs; // true during startup - QLocalServer* uriServer; - OptionsModel *optionsModel; - #ifdef ENABLE_BIP70 static bool readPaymentRequestFromFile(const QString& filename, PaymentRequestPlus& request); bool processPaymentRequest(const PaymentRequestPlus& request, SendCoinsRecipient& recipient); @@ -155,6 +151,10 @@ private: void initNetManager(); QNetworkAccessManager* netManager; // Used to fetch payment requests #endif + + bool saveURIs; // true during startup + QLocalServer* uriServer; + OptionsModel *optionsModel; }; #endif // BITCOIN_QT_PAYMENTSERVER_H diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 9d7f9f765c..602f0b754a 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -439,7 +439,7 @@ static UniValue masternode_payments(const JSONRPCRequest& request) // A temporary vector which is used to sort results properly (there is no "reverse" in/for UniValue) std::vector vecPayments; - while (vecPayments.size() < std::abs(nCount) != 0 && pindex != nullptr) { + while (vecPayments.size() < std::abs(nCount) && pindex != nullptr) { CBlock block; if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) { diff --git a/src/test/cachemultimap_tests.cpp b/src/test/cachemultimap_tests.cpp index 0deffa04ab..1fa2cd0e13 100644 --- a/src/test/cachemultimap_tests.cpp +++ b/src/test/cachemultimap_tests.cpp @@ -11,15 +11,6 @@ BOOST_FIXTURE_TEST_SUITE(cachemultimap_tests, BasicTestingSetup) -static void DumpMap(const CacheMultiMap& cmmap) -{ - const CacheMultiMap::list_t& listItems = cmmap.GetItemList(); - for(CacheMultiMap::list_cit it = listItems.begin(); it != listItems.end(); ++it) { - const CacheItem& item = *it; - std::cout << item.key << " : " << item.value << std::endl; - } -} - static bool Compare(const CacheMultiMap& cmmap1, const CacheMultiMap& cmmap2) { if(cmmap1.GetMaxSize() != cmmap2.GetMaxSize()) { diff --git a/src/validation.cpp b/src/validation.cpp index 31c06e0359..021323b17d 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -162,8 +162,6 @@ CBlockPolicyEstimator feeEstimator; CTxMemPool mempool(&feeEstimator); std::atomic_bool g_is_mempool_loaded{false}; -static void CheckBlockIndex(const Consensus::Params& consensusParams); - // Internal stuff namespace { CBlockIndex* pindexBestInvalid = nullptr; diff --git a/src/validation.h b/src/validation.h index 025e54f66c..949b07c953 100644 --- a/src/validation.h +++ b/src/validation.h @@ -263,9 +263,6 @@ void PruneBlockFilesManual(int nManualPruneHeight); bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool* pfMissingInputs, bool bypass_limits, const CAmount nAbsurdFee, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main); -static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, - bool* pfMissingInputs, int64_t nAcceptTime, bool bypass_limits, - const CAmount nAbsurdFee, bool test_accept = false); bool GetUTXOCoin(const COutPoint& outpoint, Coin& coin); int GetUTXOHeight(const COutPoint& outpoint);