diff options
author | Angel Garcia Gomez <angelgarcia@google.com> | 2015-10-05 11:15:39 +0000 |
---|---|---|
committer | Angel Garcia Gomez <angelgarcia@google.com> | 2015-10-05 11:15:39 +0000 |
commit | 199e5232b3f57d007bf13d803bd2bf1260e71072 (patch) | |
tree | 6c90654e95d5ab4feed09c85a0eff6384a3a31e2 /clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp | |
parent | 72207b167c975173e4b180d6cfbea1e537a3abec (diff) | |
download | bcm5719-llvm-199e5232b3f57d007bf13d803bd2bf1260e71072.tar.gz bcm5719-llvm-199e5232b3f57d007bf13d803bd2bf1260e71072.zip |
Document a bug in loop-convert and fix one of its subcases.
Summary: Now that we prioritize copying trivial types over using const-references where possible, I found some cases where, after the transformation, the loop was using the address of the local copy instead of the original object.
Reviewers: klimek
Subscribers: alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D13431
llvm-svn: 249300
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, 11 insertions, 1 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 42a5d5cdc37..145ea7f0be0 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 @@ -97,7 +97,7 @@ void f() { // CHECK-FIXES-NEXT: Tea.g(); } -void constArray() { +const int *constArray() { for (int I = 0; I < N; ++I) { printf("2 * %d = %d\n", ConstArr[I], ConstArr[I] + ConstArr[I]); } @@ -112,6 +112,16 @@ void constArray() { // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (const auto & Elem : NonCopy) // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", Elem.X, Elem.X + Elem.X); + + bool Something = false; + for (int I = 0; I < N; ++I) { + if (Something) + return &ConstArr[I]; + } + // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (const auto & Elem : ConstArr) + // CHECK-FIXES-NEXT: if (Something) + // CHECK-FIXES-NEXT: return &Elem; } struct HasArr { |