Skip to content

clang prints warnings: use reference type ... to prevent copying #767

@yurivict

Description

@yurivict

Prerequisites

  • [c] Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

In file included from /disk-samsung/freebsd-ports/math/lean/work/lean-3.48.0/src/library/predict/predict.cpp:2:
/disk-samsung/freebsd-ports/math/lean/work/lean-3.48.0/src/library/predict/mepo.cpp:30:19: warning: loop variable 's' creates a copy from type 'const std::__hash_map_const_iterator<std::__hash_const_iterator<std::__hash_node<std::__hash_value_type<long, double>, void *> *>>::value_type' (aka 'const pair<const long, double>') [-Wrange-loop-construct]
  for (const auto s : syms1)
                  ^
/disk-samsung/freebsd-ports/math/lean/work/lean-3.48.0/src/library/predict/mepo.cpp:30:8: note: use reference type 'const std::__hash_map_const_iterator<std::__hash_const_iterator<std::__hash_node<std::__hash_value_type<long, double>, void *> *>>::value_type &' (aka 'const pair<const long, double> &') to prevent copying
  for (const auto s : syms1)
       ^~~~~~~~~~~~~~
                  &
In file included from /disk-samsung/freebsd-ports/math/lean/work/lean-3.48.0/src/library/predict/predict.cpp:3:
/disk-samsung/freebsd-ports/math/lean/work/lean-3.48.0/src/library/predict/nbayes.cpp:66:19: warning: loop variable 'sv' creates a copy from type 'const std::__hash_map_const_iterator<std::__hash_const_iterator<std::__hash_node<std::__hash_value_type<long, long>, void *> *>>::value_type' (aka 'const pair<const long, long>') [-Wrange-loop-construct]
  for (const auto sv : sfreqh) {
                  ^
/disk-samsung/freebsd-ports/math/lean/work/lean-3.48.0/src/library/predict/nbayes.cpp:66:8: note: use reference type 'const std::__hash_map_const_iterator<std::__hash_const_iterator<std::__hash_node<std::__hash_value_type<long, long>, void *> *>>::value_type &' (aka 'const pair<const long, long> &') to prevent copying
  for (const auto sv : sfreqh) {
       ^~~~~~~~~~~~~~~
                  &

Such warnings usually mean that the code wastes some CPU cycles on unnecessary object copying.

Steps to Reproduce

regular build

Versions

lean-3.48.0
clang-14
FreeBSD 13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions