https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94695
Bug ID: 94695
Summary: Implement -Wrange-loop-analysis
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mpolacek at gcc dot gnu.org
Target Milestone: ---
This options contains a sub-option -Wrange-loop-construct which warns about:
#include <string>
#include <vector>
int main()
{
std::vector<std::string> lol;
for (const auto it : lol) { }
}
<source>:7:21: warning: loop variable 'it' creates a copy from type 'const
std::__cxx11::basic_string<char>' [-Wrange-loop-construct]
for (const auto it : lol) { }
^
<source>:7:10: note: use reference type 'const std::__cxx11::basic_string<char>
&' to prevent copying
for (const auto it : lol) { }
^~~~~~~~~~~~~~~
&
1 warning generated.
We should consider adding something like that, too, in GCC 11.