diff options
author | Alexander Kornienko <alexfh@google.com> | 2016-01-29 15:21:32 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2016-01-29 15:21:32 +0000 |
commit | 40d307d12089fb7ee05dd5900cea6362fce89f1f (patch) | |
tree | 76db2abc04733078aea63644c1ff0d624c9628aa /clang-tools-extra/docs/clang-tidy/checks/performance-implicit-cast-in-loop.rst | |
parent | 865a7d8aab2d2ba12a5f2526fc746e580878ebaf (diff) | |
download | bcm5719-llvm-40d307d12089fb7ee05dd5900cea6362fce89f1f.tar.gz bcm5719-llvm-40d307d12089fb7ee05dd5900cea6362fce89f1f.zip |
[clang-tidy] Move implicit-cast-in-loop check to upstream.
Summary: This is implemented originally by Alex Pilkiewicz (pilki@google.com).
Reviewers: alexfh
Subscribers: cfe-commits
Patch by Haojian Wu!
Differential Revision: http://reviews.llvm.org/D16721
llvm-svn: 259195
Diffstat (limited to 'clang-tools-extra/docs/clang-tidy/checks/performance-implicit-cast-in-loop.rst')
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/performance-implicit-cast-in-loop.rst | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance-implicit-cast-in-loop.rst b/clang-tools-extra/docs/clang-tidy/checks/performance-implicit-cast-in-loop.rst new file mode 100644 index 00000000000..f7e3cdcc6e7 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/performance-implicit-cast-in-loop.rst @@ -0,0 +1,19 @@ +performance-implicit-cast-in-loop +================================= + +This warning appears in range-based loop with 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 cast has been added, which can for example result in +expensive deep copies. + +Example: + +.. code:: 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 cast, resulting in a copy of the vectors. + +The easiest solution is usually to use "const auto&" instead of writing the type +manually. |