summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/test/clang-tidy')
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp35
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-loop-convert-const.cpp2
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp20
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-loop-convert-negative.cpp27
4 files changed, 56 insertions, 28 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 ae5308ee963..dc95434c8e2 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
@@ -168,6 +168,41 @@ struct HasArr {
}
};
+struct HasIndirectArr {
+ HasArr HA;
+ void implicitThis() {
+ for (int I = 0; I < N; ++I) {
+ printf("%d", HA.Arr[I]);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
+ // CHECK-FIXES: for (int Elem : HA.Arr)
+ // CHECK-FIXES-NEXT: printf("%d", Elem);
+
+ for (int I = 0; I < N; ++I) {
+ printf("%d", HA.ValArr[I].X);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
+ // CHECK-FIXES: for (auto & Elem : HA.ValArr)
+ // CHECK-FIXES-NEXT: printf("%d", Elem.X);
+ }
+
+ void explicitThis() {
+ for (int I = 0; I < N; ++I) {
+ printf("%d", this->HA.Arr[I]);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
+ // CHECK-FIXES: for (int Elem : this->HA.Arr)
+ // CHECK-FIXES-NEXT: printf("%d", Elem);
+
+ for (int I = 0; I < N; ++I) {
+ printf("%d", this->HA.ValArr[I].X);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
+ // CHECK-FIXES: for (auto & Elem : this->HA.ValArr)
+ // CHECK-FIXES-NEXT: printf("%d", Elem.X);
+ }
+};
+
// Loops whose bounds are value-dependent should not be converted.
template <int N>
void dependentExprBound() {
diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-const.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-const.cpp
index 7aec28454fa..2f64627c8de 100644
--- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-const.cpp
+++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-const.cpp
@@ -341,7 +341,7 @@ class TestInsideConstFunction {
copyArg(Ints[I]);
}
// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop
- // CHECK-FIXES: for (int Elem : Ints)
+ // CHECK-FIXES: for (int Int : Ints)
for (int I = 0; I < N; ++I) {
Array[I].constMember(0);
diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
index 3bce23e2585..104b2b2e5cd 100644
--- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
+++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -237,6 +237,26 @@ void refs_and_vals() {
}
}
+struct MemberNaming {
+ const static int N = 10;
+ int Ints[N], Ints_[N];
+ void loops() {
+ for (int I = 0; I < N; ++I) {
+ printf("%d\n", Ints[I]);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
+ // CHECK-FIXES: for (int Int : Ints)
+ // CHECK-FIXES-NEXT: printf("%d\n", Int);
+
+ for (int I = 0; I < N; ++I) {
+ printf("%d\n", Ints_[I]);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
+ // CHECK-FIXES: for (int Int : Ints_)
+ // CHECK-FIXES-NEXT: printf("%d\n", Int);
+ }
+};
+
} // namespace NamingAlias
namespace NamingConlict {
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 b0727f527bf..c038437298e 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
@@ -92,33 +92,6 @@ void multipleArrays() {
}
}
-struct HasArr {
- int Arr[N];
- Val ValArr[N];
-};
-
-struct HasIndirectArr {
- HasArr HA;
- void implicitThis() {
- for (int I = 0; I < N; ++I) {
- printf("%d", HA.Arr[I]);
- }
-
- for (int I = 0; I < N; ++I) {
- printf("%d", HA.ValArr[I].X);
- }
- }
-
- void explicitThis() {
- for (int I = 0; I < N; ++I) {
- printf("%d", this->HA.Arr[I]);
- }
-
- for (int I = 0; I < N; ++I) {
- printf("%d", this->HA.ValArr[I].X);
- }
- }
-};
}
namespace NegativeIterator {
OpenPOWER on IntegriCloud