[Refactor] Fix some -Wdeprecated-copy warnings #2089
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix the
-Wdeprecated-copywarnings listed in #2076Background
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)
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/CMasternodeuse 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.CTransactionhas an explicit copy-assignment operator, but uses the implicit copy-ctor inCMerkleTxconstructor.CFeeRateandCTxMemPoolEntryhave explicitly defined copy ctor, which can (and should, for the rule-of-three) be replaced by the default one (Remove redundant explicitly defined copy ctors bitcoin/bitcoin#11161).Note
Reason why these warnings pop up just now.
Since Clang 10.0 and GCC 9.3,
-Wextraenables-Wdeprecated-copyby 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)