diff options
author | Angel Garcia Gomez <angelgarcia@google.com> | 2015-09-01 15:05:15 +0000 |
---|---|---|
committer | Angel Garcia Gomez <angelgarcia@google.com> | 2015-09-01 15:05:15 +0000 |
commit | 692cbb5bb0382e8af2a9115cfcee70d697842945 (patch) | |
tree | 4258f55b04c61116d4e76639dfff5b4c90f4c63c /clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp | |
parent | 7a9495bcd59402b888207cae6bdb927643cc81a5 (diff) | |
download | bcm5719-llvm-692cbb5bb0382e8af2a9115cfcee70d697842945.tar.gz bcm5719-llvm-692cbb5bb0382e8af2a9115cfcee70d697842945.zip |
Fix several corner cases for loop-convert check.
Summary: Reduced the amount of wrong conversions of this check.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D12530
llvm-svn: 246550
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 | 35 |
1 files changed, 27 insertions, 8 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 1182b18a9d3..9d3b211bd77 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 @@ -494,12 +494,12 @@ void noContainer() { for (auto i = 0; i < v.size(); ++i) { } // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : v) { + // CHECK-FIXES: for (const auto & elem : v) { for (auto i = 0; i < v.size(); ++i) ; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : v) + // CHECK-FIXES: for (const auto & elem : v) } struct NoBeginEnd { @@ -509,15 +509,15 @@ struct NoBeginEnd { struct NoConstBeginEnd { NoConstBeginEnd(); unsigned size() const; - unsigned begin(); - unsigned end(); + unsigned* begin(); + unsigned* end(); }; struct ConstBeginEnd { ConstBeginEnd(); unsigned size() const; - unsigned begin() const; - unsigned end() const; + unsigned* begin() const; + unsigned* end() const; }; // Shouldn't transform pseudo-array uses if the container doesn't provide @@ -535,13 +535,32 @@ void NoBeginEndTest() { for (unsigned i = 0, e = CBE.size(); i < e; ++i) { } // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : CBE) { + // CHECK-FIXES: for (const auto & elem : CBE) { const ConstBeginEnd const_CBE; for (unsigned i = 0, e = const_CBE.size(); i < e; ++i) { } // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : const_CBE) { + // CHECK-FIXES: for (const auto & elem : const_CBE) { +} + +struct DerefByValue { + DerefByValue(); + struct iter { unsigned operator*(); }; + unsigned size() const; + iter begin(); + iter end(); + unsigned operator[](int); +}; + +void DerefByValueTest() { + DerefByValue DBV; + for (unsigned i = 0, e = DBV.size(); i < e; ++i) { + printf("%d\n", DBV[i]); + } + // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (auto && elem : DBV) { + } } // namespace PseudoArray |