Skip to content

Missing 'const' causes compiler warning #571

@gwillen

Description

@gwillen
wallet/wallet.cpp:2943:56: warning: loop variable 'value' has type 'const std::pair<CAsset, CAmount> &' (aka 'const pair<CAsset, long long> &') but is initialized with type 'value_type' (aka 'pair<const CAsset, long long>') resulting in a copy [-Wrange-loop-analysis]
                for (const std::pair<CAsset, CAmount>& value : mapValue) {
                                                       ^
wallet/wallet.cpp:2943:22: note: use non-reference type 'std::pair<CAsset, CAmount>' (aka 'pair<CAsset, long long>') to keep the copy or type 'const value_type &' (aka 'const pair<const CAsset, long long> &') to prevent copying
                for (const std::pair<CAsset, CAmount>& value : mapValue) {
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wallet/wallet.cpp:3109:55: warning: loop variable 'assetChange' has type 'const std::pair<CAsset, CAmount> &' (aka 'const pair<CAsset, long long> &') but is initialized with type 'const value_type' (aka 'const pair<const CAsset, long long>') resulting in a copy [-Wrange-loop-analysis]
                for(const std::pair<CAsset, CAmount>& assetChange : mapChange) {
                                                      ^
wallet/wallet.cpp:3109:21: note: use non-reference type 'std::pair<CAsset, CAmount>' (aka 'pair<CAsset, long long>') to keep the copy or type 'const value_type &' (aka 'const pair<const CAsset, long long> &') to prevent copying
                for(const std::pair<CAsset, CAmount>& assetChange : mapChange) {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

This should be fixed by changing (in both cases) CAsset to "const CAsset", OR switching to "const auto&".

I assume I'm seeing this because I'm on a mac (hence clang instead of gcc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions