1// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
2// RUN: -config="{CheckOptions: {modernize-loop-convert.NamingStyle: 'lower_case'}}" \
3// RUN: -- -I %S/Inputs/loop-convert
4
5#include "structures.h"
6
7const int n = 10;
8int arr[n];
9int nums[n];
10int nums_[n];
11
12void naming() {
13 for (int i = 0; i < n; ++i) {
14 printf("%d\n", arr[i]);
15 }
16 // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
17 // CHECK-FIXES: for (int i : arr)
18 // CHECK-FIXES-NEXT: printf("%d\n", i);
19
20 for (int i = 0; i < n; ++i) {
21 printf("%d\n", nums[i]);
22 }
23 // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
24 // CHECK-FIXES: for (int num : nums)
25 // CHECK-FIXES-NEXT: printf("%d\n", num);
26
27 for (int i = 0; i < n; ++i) {
28 printf("%d\n", nums_[i]);
29 }
30 // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
31 // CHECK-FIXES: for (int num : nums_)
32 // CHECK-FIXES-NEXT: printf("%d\n", num);
33
34 int num = 0;
35 for (int i = 0; i < n; ++i) {
36 printf("%d\n", nums[i] + num);
37 }
38 // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
39 // CHECK-FIXES: for (int i : nums)
40 // CHECK-FIXES-NEXT: printf("%d\n", i + num);
41}
42

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-lowercase.cpp