diff options
author | Manuel Klimek <klimek@google.com> | 2015-09-23 18:40:47 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2015-09-23 18:40:47 +0000 |
commit | 143b6442381dc7a667fc17c75dfc1d8c6c52fdfe (patch) | |
tree | 2bc2b406b8d307f2954fd3beab6b311bb28e3d8a /clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp | |
parent | e1440256520aba388015a15f5c273afa799271d5 (diff) | |
download | bcm5719-llvm-143b6442381dc7a667fc17c75dfc1d8c6c52fdfe.tar.gz bcm5719-llvm-143b6442381dc7a667fc17c75dfc1d8c6c52fdfe.zip |
Fix loop-convert for const references to containers.
Previously we would use a non-const loop variable in the range-based
loop for:
void f(const std::vector<int> &v) {
for (size_t i = 0; i < v.size(); ++i) {
Now we use const auto&.
Note that we'll also want to use a copy at least for simple types.
llvm-svn: 248418
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp index dd16cb26f62..d3908b9126b 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp @@ -544,6 +544,18 @@ void constness() { // CHECK-FIXES-NEXT: sum += elem + 2; } +void ConstRef(const dependent<int>& ConstVRef) { + int sum = 0; + // FIXME: This does not work with size_t (probably due to the implementation + // of dependent); make dependent work exactly like a std container type. + for (int i = 0; i < ConstVRef.size(); ++i) { + sum += ConstVRef[i]; + } + // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (const auto & elem : ConstVRef) + // CHECK-FIXES-NEXT: sum += elem; +} + // Check for loops that don't mention containers. void noContainer() { for (auto i = 0; i < v.size(); ++i) { |