1// RUN: %check_clang_tidy %s readability-identifier-length %t \
2// RUN: -config='{CheckOptions: \
3// RUN: {readability-identifier-length.IgnoredVariableNames: "^[xy]$"}}' \
4// RUN: -- -fexceptions
5
6struct myexcept {
7 int val;
8};
9
10struct simpleexcept {
11 int other;
12};
13
14void doIt();
15
16void tooShortVariableNames(int z)
17// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: parameter name 'z' is too short, expected at least 3 characters [readability-identifier-length]
18{
19 int i = 5;
20 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable name 'i' is too short, expected at least 3 characters [readability-identifier-length]
21
22 int jj = z;
23 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable name 'jj' is too short, expected at least 3 characters [readability-identifier-length]
24
25 for (int m = 0; m < 5; ++m)
26 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: loop variable name 'm' is too short, expected at least 2 characters [readability-identifier-length]
27 {
28 doIt();
29 }
30
31 try {
32 doIt();
33 } catch (const myexcept &x)
34 // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: exception variable name 'x' is too short, expected at least 2 characters [readability-identifier-length]
35 {
36 doIt();
37 }
38}
39
40void longEnoughVariableNames(int n) // argument 'n' ignored by default configuration
41{
42 int var = 5;
43
44 for (int i = 0; i < 42; ++i) // 'i' is default allowed, for historical reasons
45 {
46 doIt();
47 }
48
49 for (int kk = 0; kk < 42; ++kk) {
50 doIt();
51 }
52
53 try {
54 doIt();
55 } catch (const simpleexcept &e) // ignored by default configuration
56 {
57 doIt();
58 } catch (const myexcept &ex) {
59 doIt();
60 }
61
62 int x = 5; // ignored by configuration
63}
64

source code of clang-tools-extra/test/clang-tidy/checkers/readability/identifier-length.cpp