leanprover-community / leanprover-community/lean
clang prints warnings: use reference type ... to prevent copying
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 434
- Forks
- 79
- PR merge metrics
- No merged PRs in 30d
Description
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.
- Specifically, check out the wishlist, open RFCs,
or feature requests.
- Specifically, check out the wishlist, open RFCs,
- Reduced the issue to a self-contained, reproducible test case.
- Checked that your issue isn't already filed.
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the reported range-based loops in src/library/predict/mepo.cpp and src/library/predict/nbayes.cpp, starting with a regular clang build to reproduce the warnings. Update the affected loops so the unnecessary-copy warnings are gone, then rebuild to confirm the warnings no longer appear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100