2016-01-29 23:54:26 +08:00
|
|
|
.. title:: clang-tidy - performance-for-range-copy
|
|
|
|
|
|
|
|
performance-for-range-copy
|
|
|
|
==========================
|
|
|
|
|
|
|
|
Finds C++11 for ranges where the loop variable is copied in each iteration but
|
|
|
|
it would suffice to obtain it by const reference.
|
|
|
|
|
|
|
|
The check is only applied to loop variables of types that are expensive to copy
|
|
|
|
which means they are not trivially copyable or have a non-trivial copy
|
|
|
|
constructor or destructor.
|
|
|
|
|
2016-02-15 11:27:54 +08:00
|
|
|
To ensure that it is safe to replace the copy with a const reference the
|
|
|
|
following heuristic is employed:
|
2016-01-29 23:54:26 +08:00
|
|
|
|
|
|
|
1. The loop variable is const qualified.
|
|
|
|
2. The loop variable is not const, but only const methods or operators are
|
|
|
|
invoked on it, or it is used as const reference or value argument in
|
|
|
|
constructors or function calls.
|
2016-08-31 21:21:18 +08:00
|
|
|
|
|
|
|
Options
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. option:: WarnOnAllAutoCopies
|
|
|
|
|
|
|
|
When non-zero, warns on any use of `auto` as the type of the range-based for
|
|
|
|
loop variable. Default is `0`.
|