A range for copies each string or container element into a loop variable that is only read
What it finds
for (std::string s : names) copies every element. When the body does not change the copy, const std::string &s reads the elements where they are. Loop variables the body assigns, changes with a member function, moves from or passes on are left alone.
From the rule's source, range_for_copies_element.rs.
Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/cpp:range-for-copies-element" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/cpp:range-for-copies-element] reason="..."tx0 explain tx0/cpp:range-for-copies-element shows the same in the terminal. Found a false positive? Report it.