Top level const
in declarations is problematic for many reasons:
- It is often a typo, where one wanted to denote a const reference. For example
bool PSBTInputSignedAndVerified(const PartiallySignedTransaction psbt, ...
is missing the&
. This will create a redundant copy of the value. - In constructors it prevents move construction.
- It can incorrectly imply some data is const, like in an imaginary example
std::span<int> Shuffle(const std::span<int>);
, where theint
s are not const. - The compiler ignores the
const
from the declaration in the implementation. - It isn’t used consistently anyway, not even on the same line.
Fix all issues by:
- Using a const reference to avoid a copy, where read-only of the value is intended. This is only done for values that may be expensive to copy.
- Using move-construction to avoid a copy
- Applying
readability-avoid-const-params-in-decls
via clang-tidy