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

[Bug] Compiler warnings #2076

Closed
kyeno opened this issue Dec 19, 2020 · 6 comments
Closed

[Bug] Compiler warnings #2076

kyeno opened this issue Dec 19, 2020 · 6 comments
Assignees
Milestone

Comments

@kyeno
Copy link

kyeno commented Dec 19, 2020

PIVX master branch

commit 8d4f649

Machine specs:

  • OS: Gentoo Linux old-hardened profile, grsec+PaX enabled kernel
  • CPU: 32bit x86 Core2Quad Q8200S
  • RAM: 8GB DDR2 800MHz
  • Thread model: posix
  • gcc version 9.3.0 (Gentoo Hardened 9.3.0-r2 p4), default linker
  • Compiling with --without-gui

Compiler throws multiple warnings; mostly -Wdeprecated-copy, but also one potentially dangerous -Wclass-memaccess.

The scary memcpy() problem:

compressor.cpp: In member function 'bool CScriptCompressor::IsToKeyID(CKeyID&) const':
compressor.cpp:16:37: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class CKeyID' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   16 |         memcpy(&hash, &script[3], 20);
      |                                     ^

compressor.cpp: In member function 'bool CScriptCompressor::IsToScriptID(CScriptID&) const':
compressor.cpp:25:37: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class CScriptID' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   25 |         memcpy(&hash, &script[2], 20);
      |                                     ^

The ones causing most of the warnings and being repeated a lot during the compilation (in various references):

masternode.h: In lambda function:
masternode.h:143:83: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  143 |     void SetLastPing(const CMasternodePing& _lastPing) { WITH_LOCK(cs, lastPing = _lastPing;); }
      |                                                                                   ^~~~~~~~~
masternode.cpp: In constructor 'CMasternodeBroadcast::CMasternodeBroadcast(CService, CTxIn, CPubKey, CPubKey, int, const CMasternodePing&)':
masternode.cpp:217:16: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  217 |     lastPing = _lastPing;
      |                ^~~~~~~~~
wallet/wallet.h: In constructor 'CMerkleTx::CMerkleTx(const CTransaction&)':
wallet/wallet.h:871:60: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  871 |     CMerkleTx(const CTransaction& txIn) : CTransaction(txIn)
      |                                                            ^
./sync.h:207:45: note: in definition of macro 'WITH_LOCK'
  207 | #define WITH_LOCK(cs, code) [&] { LOCK(cs); code; }()
      |                                             ^~~~
./primitives/transaction.h:269:19: note: because 'CTransaction' has user-provided 'CTransaction& CTransaction::operator=(const CTransaction&)'
  269 |     CTransaction& operator=(const CTransaction& tx);
      |                   ^~~~~~~~

All the others referred either a bit less often, or occuring just once:

init.cpp: In function 'bool AppInit2()':
init.cpp:1099:41: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
 1099 |             ::minRelayTxFee = CFeeRate(n);
      |                                         ^
miner.cpp: In function 'CBlockTemplate* CreateNewBlock(const CScript&, CWallet*, bool, std::vector<CStakeableOutput>*)':
miner.cpp:295:36: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  295 |                 porphan->feeRate = feeRate;
      |                                    ^~~~~~~
txmempool.cpp: In copy constructor 'CTxMemPoolEntry::CTxMemPoolEntry(const CTxMemPoolEntry&)':
txmempool.cpp:45:13: warning: implicitly-declared 'CTxMemPoolEntry& CTxMemPoolEntry::operator=(const CTxMemPoolEntry&)' is deprecated [-Wdeprecated-copy]
   45 |     *this = other;
      |             ^~~~~
policy/feerate.h:27:5: note: because 'CFeeRate' has user-provided 'CFeeRate::CFeeRate(const CFeeRate&)'
   27 |     CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
      |     ^~~~~~~~
masternode.cpp: In member function 'bool CMasternodePing::CheckAndUpdate(int&, bool, bool)':
masternode.cpp:654:71: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  654 |                 mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = *this;
      |                                                                       ^~~~
./coincontrol.h: In member function 'void CCoinControl::SetNull()':
./coincontrol.h:58:30: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
   58 |         nFeeRate = CFeeRate(0);
      |                              ^
In function 'char* strncpy(char*, const char*, size_t)',
    inlined from 'CMessageHeader::CMessageHeader(const unsigned char (&)[4], const char*, unsigned int)' at protocol.cpp:130:12:
/usr/include/bits/string_fortified.h:106:34: warning: 'char* __builtin_strncpy(char*, const char*, unsigned int)' specified bound 12 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
script/sign.cpp: In member function 'virtual bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>&, const CKeyID&, const CScript&, SigVersion) const':
script/sign.cpp:30:31: warning: catching polymorphic type 'class std::logic_error' by value [-Wcatch-value=]
   30 |     } catch (std::logic_error ex) {
      |                               ^~
spork.h: In member function 'CSporkMessage& CSporkMessage::operator=(const CSporkMessage&)':
spork.h:33:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
   33 | class CSporkMessage : public CSignedMessage
      |       ^~~~~~~~~~~~~
./wallet/wallet.h: In constructor 'CMerkleTx::CMerkleTx(const CTransaction&)':
./wallet/wallet.h:871:60: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  871 |     CMerkleTx(const CTransaction& txIn) : CTransaction(txIn)
      |                                                            ^
In file included from sapling/sapling_operation.cpp:5:
./sapling/sapling_operation.h: In member function 'CTransaction SaplingOperation::getFinalTx()':
./sapling/sapling_operation.h:107:40: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  107 |     CTransaction getFinalTx() { return finalTx; }
      |                                        ^~~~~~~
policy/fees.cpp: In constructor 'CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate&)':
policy/fees.cpp:301:84: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  301 |     minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee;
      |                                                                                    ^~~~~~~~~~~~
./budget/budgetvote.h: In member function 'CBudgetVote& CBudgetVote::operator=(const CBudgetVote&)':
./budget/budgetvote.h:17:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
   17 | class CBudgetVote : public CSignedMessage
      |       ^~~~~~~~~~~
./budget/finalizedbudgetvote.h: In member function 'CFinalizedBudgetVote& CFinalizedBudgetVote::operator=(const CFinalizedBudgetVote&)':
./budget/finalizedbudgetvote.h:18:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
   18 | class CFinalizedBudgetVote : public CSignedMessage
      |       ^~~~~~~~~~~~~~~~~~~~

Those seem to be all I managed to catch and filter out/unify during the quickly scrolling compilation terminal. ;)

@random-zebra
Copy link

Thanks for reporting these @kyeno .
They are all fixed with the PRs above (I have verified that, with all of them, there are no warnings on gcc v9.3.0 during the compilation of a no-GUI wallet).

@kyeno
Copy link
Author

kyeno commented Dec 21, 2020

Hey, thank you @random-zebra!
I will check on my machine soon too. :)

Fuzzbawls added a commit that referenced this issue Dec 21, 2020
… in CreateSig

2523f81 [Refactor] Pass caught logic_error by reference in CreateSig (random-zebra)

Pull request description:

  Exceptions/errors caught should be passed by reference.
  If the catch-block is not modifying the exception/error, the reference should be `const` (same as we did way back in #979)

  Fix one instance in `TransactionSignatureCreator::CreateSig` where we are passing a logic_error by copy, causing the `catching polymorphic type` warning reported in #2076

ACKs for top commit:
  furszy:
    utACK 2523f81
  Fuzzbawls:
    utACK 2523f81

Tree-SHA512: d13a0a2a9372610f3a5e67016053afbbac94d30f5d3dd8568352f7fd99356336058405f8526eaf1e6f751e2e48d7405425ad7a8a3a3f0ba8c6db620d12710ad2
@kyeno
Copy link
Author

kyeno commented Dec 29, 2020

Hey!
Took me a while but I just ran another recompile of master 57c807e

The environment and compilation params were identical as in the first case.

It's less than it was, but still throws quite a bit of warnings:

memcpy() warning:

compressor.cpp: In member function 'bool CScriptCompressor::IsToKeyID(CKeyID&) const':
compressor.cpp:16:37: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class CKeyID' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   16 |         memcpy(&hash, &script[3], 20);
      |                                     ^

Ones generating most warnings during the whole compile and linking:

wallet/wallet.h: In constructor 'CMerkleTx::CMerkleTx(const CTransaction&)':
wallet/wallet.h:871:60: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  871 |     CMerkleTx(const CTransaction& txIn) : CTransaction(txIn)
masternode.h:88:22: note: because 'CMasternodePing' has user-provided 'CMasternodePing& CMasternodePing::operator=(CMasternodePing)'
   88 |     CMasternodePing& operator=(CMasternodePing from)
      |                      ^~~~~~~~
masternode.h:88:48: note:   initializing argument 1 of 'CMasternodePing& CMasternodePing::operator=(CMasternodePing)'
   88 |     CMasternodePing& operator=(CMasternodePing from)
      |                                ~~~~~~~~~~~~~~~~^~~~
masternode.h: In lambda function:
masternode.h:143:83: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  143 |     void SetLastPing(const CMasternodePing& _lastPing) { WITH_LOCK(cs, lastPing = _lastPing;); }
      |                                                                                   ^~~~~~~~~
./sync.h:207:45: note: in definition of macro 'WITH_LOCK'
  207 | #define WITH_LOCK(cs, code) [&] { LOCK(cs); code; }()
      |                                             ^~~~
./primitives/transaction.h:269:19: note: because 'CTransaction' has user-provided 'CTransaction& CTransaction::operator=(const CTransaction&)'
  269 |     CTransaction& operator=(const CTransaction& tx);
      |                   ^~~~~~~~

Remainder

./budget/budgetvote.h: In member function 'CBudgetVote& CBudgetVote::operator=(const CBudgetVote&)':
./budget/budgetvote.h:17:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
   17 | class CBudgetVote : public CSignedMessage
      |       ^~~~~~~~~~~
./messagesigner.h:62:5: note: because 'CSignedMessage' has user-provided 'CSignedMessage::CSignedMessage(const CSignedMessage&)'
   62 |     CSignedMessage(const CSignedMessage& other)
      |     ^~~~~~~~~~~~~~
budget/budgetmanager.cpp: In lambda function:
budget/budgetmanager.cpp:1098:73: note: synthesized method 'CBudgetVote& CBudgetVote::operator=(const CBudgetVote&)' first required here
 1098 |             WITH_LOCK(cs_votes, mapOrphanProposalVotes[nProposalHash] = vote; );
      |                                                                         ^~~~
./budget/finalizedbudgetvote.h: In member function 'CFinalizedBudgetVote& CFinalizedBudgetVote::operator=(const CFinalizedBudgetVote&)':
./budget/finalizedbudgetvote.h:18:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
   18 | class CFinalizedBudgetVote : public CSignedMessage
      |       ^~~~~~~~~~~~~~~~~~~~
budget/budgetproposal.cpp: In member function 'bool CBudgetProposal::AddOrUpdateVote(const CBudgetVote&, std::string&)':
budget/budgetproposal.cpp:243:22: note: synthesized method 'CBudgetVote& CBudgetVote::operator=(const CBudgetVote&)' first required here
  243 |     mapVotes[hash] = vote;
      |                      ^~~~
masternode.cpp: In copy constructor 'CMasternode::CMasternode(const CMasternode&)':
masternode.cpp:92:22: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
   92 |     lastPing = other.lastPing;
      |                      ^~~~~~~~
masternode.cpp: In member function 'bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast&)':
masternode.cpp:135:28: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  135 |             lastPing = mnb.lastPing;
      |                            ^~~~~~~~
masternode.cpp: In constructor 'CMasternodeBroadcast::CMasternodeBroadcast(CService, CTxIn, CPubKey, CPubKey, int, const CMasternodePing&)':
masternode.cpp:217:16: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  217 |     lastPing = _lastPing;
      |                ^~~~~~~~~
masternode.cpp: In member function 'bool CMasternodePing::CheckAndUpdate(int&, bool, bool)':
masternode.cpp:654:71: warning: implicitly-declared 'CMasternodePing::CMasternodePing(const CMasternodePing&)' is deprecated [-Wdeprecated-copy]
  654 |                 mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = *this;
      |                                                                       ^~~~
masternode-payments.h: In member function 'CMasternodePaymentWinner& CMasternodePaymentWinner::operator=(const CMasternodePaymentWinner&)':
masternode-payments.h:159:7: warning: implicitly-declared 'CSignedMessage& CSignedMessage::operator=(const CSignedMessage&)' is deprecated [-Wdeprecated-copy]
  159 | class CMasternodePaymentWinner : public CSignedMessage
      |       ^~~~~~~~~~~~~~~~~~~~~~~~
messagesigner.h:62:5: note: because 'CSignedMessage' has user-provided 'CSignedMessage::CSignedMessage(const CSignedMessage&)'
   62 |     CSignedMessage(const CSignedMessage& other)
      |     ^~~~~~~~~~~~~~
masternode-payments.cpp: In member function 'bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner&)':
masternode-payments.cpp:512:55: note: synthesized method 'CMasternodePaymentWinner& CMasternodePaymentWinner::operator=(const CMasternodePaymentWinner&)' first required here
  512 |         mapMasternodePayeeVotes[winnerIn.GetHash()] = winnerIn;
      |                                                       ^~~~~~~~
./coincontrol.h: In member function 'void CCoinControl::SetNull()':
./coincontrol.h:58:30: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
   58 |         nFeeRate = CFeeRate(0);
      |                              ^
./policy/feerate.h:27:5: note: because 'CFeeRate' has user-provided 'CFeeRate::CFeeRate(const CFeeRate&)'
   27 |     CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
      |     ^~~~~~~~
./sapling/sapling_operation.h: In member function 'CTransaction SaplingOperation::getFinalTx()':
./sapling/sapling_operation.h:107:40: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  107 |     CTransaction getFinalTx() { return finalTx; }
      |                                        ^~~~~~~
wallet/wallet.h: In copy constructor 'CMerkleTx::CMerkleTx(const CMerkleTx&)':
wallet/wallet.h:851:7: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  851 | class CMerkleTx : public CTransaction
      |       ^~~~~~~~~
wallet/wallet.h: In copy constructor 'CWalletTx::CWalletTx(const CWalletTx&)':
wallet/wallet.h:917:7: note: synthesized method 'CMerkleTx::CMerkleTx(const CMerkleTx&)' first required here
  917 | class CWalletTx : public CMerkleTx
      |       ^~~~~~~~~
wallet/rpcwallet.cpp: In function 'UniValue listsinceblock(const JSONRPCRequest&)':
wallet/rpcwallet.cpp:2861:30: note: synthesized method 'CWalletTx::CWalletTx(const CWalletTx&)' first required here
 2861 |         CWalletTx tx = (*it).second;
      |                              ^~~~~~
wallet/rpcwallet.cpp: In function 'UniValue gettransaction(const JSONRPCRequest&)':
wallet/rpcwallet.cpp:2947:67: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
 2947 |     std::string strHex = EncodeHexTx(static_cast<CTransaction>(wtx));
      |                                                                   ^
wallet/rpcwallet.cpp: In function 'UniValue settxfee(const JSONRPCRequest&)':
wallet/rpcwallet.cpp:3573:38: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
 3573 |     payTxFee = CFeeRate(nAmount, 1000);
      |                                      ^
wallet/wallet.cpp: In member function 'void CWallet::SetBestChainInternal(CWalletDB&, const CBlockLocator&)':
wallet/wallet.cpp:491:28: note: synthesized method 'CWalletTx::CWalletTx(const CWalletTx&)' first required here
  491 |         auto wtx = wtxItem.second;
      |                            ^~~~~~
wallet/wallet.cpp: In static member function 'static bool CWallet::ParameterInteraction()':
wallet/wallet.cpp:655:43: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  655 |             CWallet::minTxFee = CFeeRate(n);
      |                                           ^
wallet/wallet.cpp:665:43: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  665 |         payTxFee = CFeeRate(nFeePerK, 1000);
      |                                           ^
wallet/wallet.cpp: In member function 'bool CWallet::FundTransaction(CMutableTransaction&, CAmount&, bool, const CFeeRate&, int&, std::string&, bool, bool, const CTxDestination&)':
wallet/wallet.cpp:2637:28: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
 2637 |     coinControl.nFeeRate = specificFeeRate;
      |                            ^~~~~~~~~~~~~~~
./pubkey.h:20:7: note: 'class CKeyID' declared here
   20 | class CKeyID : public uint160
      |       ^~~~~~
spork.cpp: In member function 'void CSporkManager::LoadSporksFromDB()':
spork.cpp:76:38: note: synthesized method 'CSporkMessage& CSporkMessage::operator=(const CSporkMessage&)' first required here
   76 |         mapSporks[spork.GetHash()] = spork;
      |                                      ^~~~~
sapling/transaction_builder.cpp: In member function 'CTransaction TransactionBuilderResult::GetTxOrThrow()':
sapling/transaction_builder.cpp:110:28: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  110 |         return maybeTx.get();
      |                            ^
./sapling/sapling_operation.h: In member function 'CTransaction SaplingOperation::getFinalTx()':
./sapling/sapling_operation.h:107:40: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  107 |     CTransaction getFinalTx() { return finalTx; }
      |                                        ^~~~~~~
test/librust/utiltest.cpp: In function 'CWalletTx GetValidSaplingReceive(const Consensus::Params&, CBasicKeyStore&, std::vector<TransparentInput>, std::vector<ShieldedDestination>, const CWallet*)':
test/librust/utiltest.cpp:80:12: note: synthesized method 'CWalletTx::CWalletTx(CWalletTx&&)' first required here
   80 |     return wtx;
      |            ^~~
miner.cpp: In function 'CBlockTemplate* CreateNewBlock(const CScript&, CWallet*, bool, std::vector<CStakeableOutput>*)':
miner.cpp:295:36: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  295 |                 porphan->feeRate = feeRate;
      |                                    ^~~~~~~
policy/fees.cpp: In constructor 'CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate&)':
policy/fees.cpp:301:84: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  301 |     minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee;
      |                                                                                    ^~~~~~~~~~~~
rpc/rawtransaction.cpp: In function 'UniValue fundrawtransaction(const JSONRPCRequest&)':
rpc/rawtransaction.cpp:523:67: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  523 |             feeRate = CFeeRate(AmountFromValue(options["feeRate"]));
      |                                                                   ^
txmempool.cpp: In copy constructor 'CTxMemPoolEntry::CTxMemPoolEntry(const CTxMemPoolEntry&)':
txmempool.cpp:45:13: warning: implicitly-declared 'CTxMemPoolEntry& CTxMemPoolEntry::operator=(const CTxMemPoolEntry&)' is deprecated [-Wdeprecated-copy]
   45 |     *this = other;
      |             ^~~~~
txmempool.cpp: In constructor 'CTxMemPool::CTxMemPool(const CFeeRate&)':
txmempool.cpp:333:29: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
  333 |     minReasonableRelayFee = _minReasonableRelayFee;
      |                             ^~~~~~~~~~~~~~~~~~~~~~
txmempool.cpp: In member function 'void CTxMemPool::removeForReorg(const CCoinsViewCache*, unsigned int, int)':
txmempool.cpp:526:130: warning: comparison of integer expressions of different signedness: 'long unsigned int' and 'const int' [-Wsign-compare]
  526 |                 if (coin.IsSpent() || ((coin.IsCoinBase() || coin.IsCoinStake()) && ((signed long)nMemPoolHeight) - coin.nHeight < Params().GetConsensus().nCoinbaseMaturity)) {
      |                                                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
txmempool.cpp: In member function 'void CTxMemPool::check(const CCoinsViewCache*) const':
txmempool.cpp:718:53: warning: comparison of integer expressions of different signedness: 'uint64_t' {aka 'long long unsigned int'} and 'int64_t' {aka 'long long int'} [-Wsign-compare]
  718 |                 assert(it->GetSizeWithDescendants() >= childSizes + it->GetTxSize());
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
txmempool.cpp: In member function 'void CTxMemPool::TrimToSize(size_t, std::vector<COutPoint>*)':
txmempool.cpp:1073:64: warning: implicitly-declared 'CFeeRate& CFeeRate::operator=(const CFeeRate&)' is deprecated [-Wdeprecated-copy]
 1073 |         maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
      |                                                                ^
validation.cpp: In function 'bool Consensus::CheckTxInputs(const CTransaction&, CValidationState&, const CCoinsViewCache&, int)':
validation.cpp:1088:58: warning: comparison of integer expressions of different signedness: 'long unsigned int' and 'const int' [-Wsign-compare]
 1088 |             if ((signed long)nSpendHeight - coin.nHeight < consensus.nCoinbaseMaturity)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./primitives/transaction.h:269:19: note: because 'CTransaction' has user-provided 'CTransaction& CTransaction::operator=(const CTransaction&)'
  269 |     CTransaction& operator=(const CTransaction& tx);
      |                   ^~~~~~~~
test/script_tests.cpp: In copy constructor 'script_tests::{anonymous}::TestBuilder::TestBuilder(const script_tests::{anonymous}::TestBuilder&)':
test/script_tests.cpp:182:7: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  182 | class TestBuilder
      |       ^~~~~~~~~~~
test/script_tests.cpp: In member function 'script_tests::{anonymous}::TestBuilder& script_tests::{anonymous}::TestBuilder::Test(bool)':
test/script_tests.cpp:291:29: note: synthesized method 'script_tests::{anonymous}::TestBuilder::TestBuilder(const script_tests::{anonymous}::TestBuilder&)' first required here
  291 |         TestBuilder copy = *this; // Make a copy so we can rollback the push.
      |                             ^~~~
test/script_tests.cpp: In function 'CScript script_tests::sign_multisig(CScript, const CKey&, CTransaction)':
test/script_tests.cpp:723:57: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
  723 |     return sign_multisig(scriptPubKey, keys, transaction);
      |                                                         ^
test/script_tests.cpp:695:74: note:   initializing argument 3 of 'CScript script_tests::sign_multisig(CScript, std::vector<CKey>, CTransaction)'
  695 | sign_multisig(CScript scriptPubKey, std::vector<CKey> keys, CTransaction transaction)
      |                                                             ~~~~~~~~~~~~~^~~~~~~~~~~
test/serialize_tests.cpp: In constructor 'serialize_tests::CSerializeMethodsTestSingle::CSerializeMethodsTestSingle(int, bool, std::string, const char*, CTransaction)':
test/serialize_tests.cpp:46:250: warning: implicitly-declared 'CTransaction::CTransaction(const CTransaction&)' is deprecated [-Wdeprecated-copy]
   46 |     CSerializeMethodsTestSingle(int intvalin, bool boolvalin, std::string stringvalin, const char* charstrvalin, CTransaction txvalin) : intval(intvalin), boolval(boolvalin), stringval(std::move(stringvalin)), charstrval(charstrvalin), txval(txvalin){}
      |                                                                                                                                                                                                                                                          ^

Rust warning:

warning: lint `intra_doc_link_resolution_failure` has been renamed to `broken_intra_doc_links`
 --> src/rust/src/rustzcash.rs:2:9
  |
2 | #![deny(intra_doc_link_resolution_failure)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `broken_intra_doc_links`
  |
  = note: `#[warn(renamed_and_removed_lints)]` on by default

@random-zebra
Copy link

@kyeno the pull requests above fix (most of) these warnings.
Though only one, out of four, has been merged on master by now.

@kyeno
Copy link
Author

kyeno commented Dec 29, 2020

@random-zebra oh, I didn't notice they were not merged; I just ran for master compile. Still, probably some new findings there too. :)

@random-zebra random-zebra added this to the 5.1.0 milestone Jan 17, 2021
furszy added a commit that referenced this issue Jan 21, 2021
ae41ebe Remove redundant explicitly defined copy ctors (Dan Raviv)
454aa37 Trivial: explicit (default) copy-constructor for CTransaction (random-zebra)
2af2306 Cleanup: Remove redundant copy-constructor for CSignedMessage (random-zebra)
e28259d Masternode: proper copy-assignment for CMasternode/CmasternodePing (random-zebra)

Pull request description:

  Fix the `-Wdeprecated-copy` warnings listed in #2076

  **Background**
  While perfectly valid in C++98, implicit generation of the copy constructor is declared as deprecated in C++11, when there is already a user-defined copy assignment operator, or vice-versa.
  The rationale behind this is the "rule of three" (https://en.cppreference.com/w/cpp/language/rule_of_three)
  > If a class requires a user-defined destructor, a user-defined copy constructor, or a user-defined copy assignment operator, it almost certainly requires all three.

  **Issue - Fix**
  We have several places that define redundant copy assignment operators (and then use the implicit copy constructor), or that do need non-default ctors/dtors but don't define copy assignment.
  (See also bitcoin#11161, which is also cherry-picked here)
  Specifically:
  - `CSignedMessage`/`CMasternodePing`/`CMasternode` use a weird copy-assignment that *swaps* with the argument (which, of course, cannot be "const" then). Here we remove all ::swap implementations, and provide actual copy assignment operators.
  - `CTransaction` has an explicit copy-assignment operator, but uses the implicit copy-ctor in `CMerkleTx` constructor.
  - `CFeeRate` and `CTxMemPoolEntry` have explicitly defined copy ctor, which can (and should, for the rule-of-three) be replaced by the default one (bitcoin#11161).

  **Note**
  Reason why these warnings pop up just now.
  Since Clang 10.0 and GCC 9.3, `-Wextra` enables `-Wdeprecated-copy` by default, and that is very spammy, especially when compiling with the QT GUI (bitcoin#15822 / bitcoin#18419).
  It is so spammy (also with `boost-1.72.0`) that Bitcoin decided to temporarily suppress this warning (bitcoin#18738) until QT fixes it upstream, and boost is definitely removed in 0.22 (bitcoin#18967)

ACKs for top commit:
  furszy:
    utACK ae41ebe

Tree-SHA512: 1f59f9f7426abbf4b7d4bb0d1ac50491eb52f776e2a018de3acc8ab381af3b69db6b9a5b60c04b48f0d495e560eaa1e3d19be03d133f230daca66ba66e766289
furszy added a commit that referenced this issue Jan 22, 2021
…eader

c223041 net: Fail instead of truncate command name in CMessageHeader (Wladimir J. van der Laan)

Pull request description:

  Fix the `-Wstringop-truncation` warning reported in #2076, cherry-picking the first commit of bitcoin#16995

  > Replace the memset/strncpy dance in `CMessageHeader::CMessageHeader` with explicit code that copies then name and asserts the length.
  >
  > This removes a warning in g++ 9.1.1 and IMO makes the code more readable by not relying on strncpy padding and silent truncation behavior.

ACKs for top commit:
  furszy:
    utACK c223041
  Fuzzbawls:
    utACK c223041

Tree-SHA512: 1c1fecc990f4d19fa5a1eb559132e81ee904af5557e3a63256d08741e201996de1f116267025317cf0c236872d121af958798a4de9bbc9a5afbcd601b768a9aa
random-zebra added a commit to random-zebra/PIVX that referenced this issue Jan 22, 2021
… opaque blobs

dea250c [Core] Migrate uint160 (CKeyID/CScriptID) to opaque blobs (random-zebra)
86a106e [Tests] Use arith_uint160 instead of uint160 in uint256_tests (random-zebra)
12240dc [BUG] fix a few places improperly checking boost::get<CKeyID> (random-zebra)

Pull request description:

  Keep going with the migration started in PIVX-Project#1395 and PIVX-Project#1414.
  This time migrate the whole class `uint160`, so it is defined as a child of `base_blob` (essentially replace `uint160` with `blob_uint160`), thus migrating `CKeyID` and `CScriptID` as well.

  Since opaque blobs (unlike the `arith_uint` classes) have trivial copy-assignment operator, this fixes the "scary" `-Wclass-memaccess` warning reported in PIVX-Project#2076 (tested before/after patch, with gcc v9.3.0)

  Bonus: this fixes also a minor bug found along the way: few places where we are checking the result of `boost::get<CKeyID>` over the pointed `CKeyID`, which shouldn't even have a `bool operator()`, and might even be un-initialized (though we always verify `IsValidDestination` before, so this is mostly redundant) instead of checking the pointer itself.

ACKs for top commit:
  furszy:
    looking good, utACK dea250c
  Fuzzbawls:
    utACK dea250c

Tree-SHA512: 2e6d6e2adfcd8a1c32941f0480b882ea801fe1816eaa0c5050efc506c0aa09f6d589d53fb13798a17ffd2858021c3a0ccd50465acbc7d5c5a71dc0fb0f398756
@random-zebra
Copy link

Guess we can close this now, if there isn't anything major left.
The rust lint warning can be ignored for now (ref: zcash/librustzcash#279)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants