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

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

Open
yurivict opened this issue Sep 5, 2022 · 0 comments
Open

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

yurivict opened this issue Sep 5, 2022 · 0 comments

Comments

@yurivict
Copy link
Contributor

yurivict commented Sep 5, 2022

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

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

1 participant