diff options
author | Angel Garcia Gomez <angelgarcia@google.com> | 2015-09-11 10:02:07 +0000 |
---|---|---|
committer | Angel Garcia Gomez <angelgarcia@google.com> | 2015-09-11 10:02:07 +0000 |
commit | bb9ca54bbe6050bfa8d111ee074f595c7fd02084 (patch) | |
tree | b7f2b082318d40067405ccc17b9d6df22b33aea4 /clang-tools-extra/test/clang-tidy/modernize-loop-convert-negative.cpp | |
parent | ef3cf01d1ccb11271c5727c8d461dcad448f4ab8 (diff) | |
download | bcm5719-llvm-bb9ca54bbe6050bfa8d111ee074f595c7fd02084.tar.gz bcm5719-llvm-bb9ca54bbe6050bfa8d111ee074f595c7fd02084.zip |
Another patch for modernize-loop-convert.
Summary:
1. Avoid converting loops that iterate over the size of a container and don't use its elements, as this would result in an unused-result warning.
2. Never capture the elements by value on lambdas, thus avoiding doing unnecessary copies and errors with non-copyable types.
3. The 'const auto &' instead of 'auto &' substitution on const containers now works on arrays and pseudoarrays as well.
4. The error about multiple replacements in the same macro call is now documented in the tests (not solved though).
5. Due to [1], I had to add a dummy usage of the range element (like "(void) *It;" or similars) on the tests that had empty loops.
6. I removed the braces from the CHECK comments. I think that there is no need for them, and they confuse vim.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D12734
llvm-svn: 247399
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/modernize-loop-convert-negative.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/modernize-loop-convert-negative.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-negative.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-negative.cpp index bbcd9a2f9b1..2d18cbebb17 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-negative.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-negative.cpp @@ -290,7 +290,6 @@ const int N = 6; dependent<int> v; dependent<int> *pv; -transparent<dependent<int>> cv; int Sum = 0; // Checks for the Index start and end: @@ -473,3 +472,41 @@ void complexContainer() { } } // namespace NegativeMultiEndCall + +namespace NoUsages { + +const int N = 6; +int arr[N] = {1, 2, 3, 4, 5, 6}; +S s; +dependent<int> v; +int Count = 0; + +void foo(); + +void f() { + for (int I = 0; I < N; ++I) {} + for (int I = 0; I < N; ++I) + printf("Hello world\n"); + for (int I = 0; I < N; ++I) + ++Count; + for (int I = 0; I < N; ++I) + foo(); + + for (S::iterator I = s.begin(), E = s.end(); I != E; ++I) {} + for (S::iterator I = s.begin(), E = s.end(); I != E; ++I) + printf("Hello world\n"); + for (S::iterator I = s.begin(), E = s.end(); I != E; ++I) + ++Count; + for (S::iterator I = s.begin(), E = s.end(); I != E; ++I) + foo(); + + for (int I = 0; I < v.size(); ++I) {} + for (int I = 0; I < v.size(); ++I) + printf("Hello world\n"); + for (int I = 0; I < v.size(); ++I) + ++Count; + for (int I = 0; I < v.size(); ++I) + foo(); +} + +} // namespace NoUsages |