summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/docs/clang-tidy/checks/performance-implicit-conversion-in-loop.rst
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/docs/clang-tidy/checks/performance-implicit-conversion-in-loop.rst')
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/performance-implicit-conversion-in-loop.rst21
1 files changed, 21 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance-implicit-conversion-in-loop.rst b/clang-tools-extra/docs/clang-tidy/checks/performance-implicit-conversion-in-loop.rst
new file mode 100644
index 00000000000..14e4d31f974
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance-implicit-conversion-in-loop.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - performance-implicit-conversion-in-loop
+
+performance-implicit-conversion-in-loop
+=======================================
+
+This warning appears in a range-based loop with a loop variable of const ref
+type where the type of the variable does not match the one returned by the
+iterator. This means that an implicit conversion happens, which can for example
+result in expensive deep copies.
+
+Example:
+
+.. code-block:: c++
+
+ map<int, vector<string>> my_map;
+ for (const pair<int, vector<string>>& p : my_map) {}
+ // The iterator type is in fact pair<const int, vector<string>>, which means
+ // that the compiler added a conversion, resulting in a copy of the vectors.
+
+The easiest solution is usually to use ``const auto&`` instead of writing the
+type manually.
OpenPOWER on IntegriCloud