summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp
diff options
context:
space:
mode:
authorAngel Garcia Gomez <angelgarcia@google.com>2015-09-08 09:01:21 +0000
committerAngel Garcia Gomez <angelgarcia@google.com>2015-09-08 09:01:21 +0000
commitd930ef76eaca107e80baa7edda864cf2eb075a24 (patch)
tree564d00004387af71db126446bfad608bd8c108ee /clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp
parentf1044c044a520e5c796fd03cea3a8b38e645a167 (diff)
downloadbcm5719-llvm-d930ef76eaca107e80baa7edda864cf2eb075a24.tar.gz
bcm5719-llvm-d930ef76eaca107e80baa7edda864cf2eb075a24.zip
Avoid using rvalue references with trivially copyable types.
Summary: When the dereference operator returns a value that is trivially copyable (like a pointer), copy it. After this change, modernize-loop-convert check can be applied to the whole llvm source code without breaking any build or test. Reviewers: alexfh, klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12675 llvm-svn: 246989
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.cpp15
1 files changed, 12 insertions, 3 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 7f31a5f4ca4..1979f1467ad 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
@@ -291,7 +291,7 @@ void f() {
I != E; ++I) {
}
// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead
- // CHECK-FIXES: for (auto && int_ptr : int_ptrs) {
+ // CHECK-FIXES: for (auto int_ptr : int_ptrs) {
}
// This container uses an iterator where the derefence type is a typedef of
@@ -564,14 +564,23 @@ struct DerefByValue {
unsigned operator[](int);
};
-void DerefByValueTest() {
+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) {
+ // CHECK-FIXES: for (auto elem : DBV) {
+ // CHECK-FIXES-NEXT: printf("%d\n", elem);
+ for (unsigned i = 0, e = DBV.size(); i < e; ++i) {
+ auto f = [DBV, i]() {};
+ printf("%d\n", DBV[i]);
+ }
+ // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+ // CHECK-FIXES: for (auto elem : DBV) {
+ // CHECK-FIXES-NEXT: auto f = [DBV, elem]() {};
+ // CHECK-FIXES-NEXT: printf("%d\n", elem);
}
} // namespace PseudoArray
OpenPOWER on IntegriCloud