1// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
2// RUN: -config='{CheckOptions: { \
3// RUN: readability-identifier-naming.MemberCase: CamelCase, \
4// RUN: readability-identifier-naming.ParameterCase: CamelCase, \
5// RUN: readability-identifier-naming.MethodCase: camelBack, \
6// RUN: readability-identifier-naming.AggressiveDependentMemberLookup: true \
7// RUN: }}' -- -fno-delayed-template-parsing
8
9int set_up(int);
10int clear(int);
11
12class Foo {
13public:
14 const int bar_baz; // comment-0
15 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for member 'bar_baz'
16 // CHECK-FIXES: {{^}} const int BarBaz; // comment-0
17
18 Foo(int Val) : bar_baz(Val) { // comment-1
19 // CHECK-FIXES: {{^}} Foo(int Val) : BarBaz(Val) { // comment-1
20 set_up(bar_baz); // comment-2
21 // CHECK-FIXES: {{^}} set_up(BarBaz); // comment-2
22 }
23
24 Foo() : Foo(0) {}
25
26 ~Foo() {
27 clear(bar_baz); // comment-3
28 // CHECK-FIXES: {{^}} clear(BarBaz); // comment-3
29 }
30
31 int getBar() const { return bar_baz; } // comment-4
32 // CHECK-FIXES: {{^}} int getBar() const { return BarBaz; } // comment-4
33};
34
35class FooBar : public Foo {
36public:
37 int getFancyBar() const {
38 return this->bar_baz; // comment-5
39 // CHECK-FIXES: {{^}} return this->BarBaz; // comment-5
40 }
41};
42
43int getBar(const Foo &Foo) {
44 return Foo.bar_baz; // comment-6
45 // CHECK-FIXES: {{^}} return Foo.BarBaz; // comment-6
46}
47
48int getBar(const FooBar &Foobar) {
49 return Foobar.bar_baz; // comment-7
50 // CHECK-FIXES: {{^}} return Foobar.BarBaz; // comment-7
51}
52
53int getFancyBar(const FooBar &Foobar) {
54 return Foobar.getFancyBar();
55}
56
57template <typename Dummy>
58class TempTest : public Foo {
59public:
60 TempTest() = default;
61 TempTest(int Val) : Foo(Val) {}
62 int getBar() const { return Foo::bar_baz; } // comment-8
63 // CHECK-FIXES: {{^}} int getBar() const { return Foo::BarBaz; } // comment-8
64 int getBar2() const { return this->bar_baz; } // comment-9
65 // CHECK-FIXES: {{^}} int getBar2() const { return this->BarBaz; } // comment-9
66};
67
68namespace Bug41122 {
69namespace std {
70
71// for this example we aren't bothered about how std::vector is treated
72template <typename T> // NOLINT
73struct vector { // NOLINT
74 void push_back(bool); // NOLINT
75 void pop_back(); // NOLINT
76}; // NOLINT
77}; // namespace std
78
79class Foo {
80 std::vector<bool> &stack;
81 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for member 'stack' [readability-identifier-naming]
82public:
83 Foo(std::vector<bool> &stack)
84 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for parameter 'stack' [readability-identifier-naming]
85 // CHECK-FIXES: {{^}} Foo(std::vector<bool> &Stack)
86 : stack(stack) {
87 // CHECK-FIXES: {{^}} : Stack(Stack) {
88 stack.push_back(true);
89 // CHECK-FIXES: {{^}} Stack.push_back(true);
90 }
91 ~Foo() {
92 stack.pop_back();
93 // CHECK-FIXES: {{^}} Stack.pop_back();
94 }
95};
96}; // namespace Bug41122
97
98namespace Bug29005 {
99class Foo {
100public:
101 int a_member_of_foo = 0;
102 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'a_member_of_foo'
103 // CHECK-FIXES: {{^}} int AMemberOfFoo = 0;
104};
105
106int main() {
107 Foo foo;
108 return foo.a_member_of_foo;
109 // CHECK-FIXES: {{^}} return foo.AMemberOfFoo;
110}
111}; // namespace Bug29005
112
113namespace CtorInits {
114template <typename T, unsigned N>
115class Container {
116 T storage[N];
117 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for member 'storage'
118 // CHECK-FIXES: {{^}} T Storage[N];
119 T *pointer = &storage[0];
120 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for member 'pointer'
121 // CHECK-FIXES: {{^}} T *Pointer = &Storage[0];
122public:
123 Container() : pointer(&storage[0]) {}
124 // CHECK-FIXES: {{^}} Container() : Pointer(&Storage[0]) {}
125};
126
127void foo() {
128 Container<int, 5> container;
129}
130} // namespace CtorInits
131
132namespace resolved_dependance {
133template <typename T>
134struct A0 {
135 int value;
136 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value'
137 A0 &operator=(const A0 &Other) {
138 value = Other.value; // A0
139 this->value = Other.value; // A0
140 // CHECK-FIXES: {{^}} Value = Other.Value; // A0
141 // CHECK-FIXES-NEXT: {{^}} this->Value = Other.Value; // A0
142 return *this;
143 }
144 void outOfLineReset();
145};
146
147template <typename T>
148void A0<T>::outOfLineReset() {
149 this->value -= value; // A0
150 // CHECK-FIXES: {{^}} this->Value -= Value; // A0
151}
152
153template <typename T>
154struct A1 {
155 int value; // A1
156 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value'
157 // CHECK-FIXES: {{^}} int Value; // A1
158 int GetValue() const { return value; } // A1
159 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for method 'GetValue'
160 // CHECK-FIXES {{^}} int getValue() const { return Value; } // A1
161 void SetValue(int Value) { this->value = Value; } // A1
162 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 'SetValue'
163 // CHECK-FIXES {{^}} void setValue(int Value) { this->Value = Value; } // A1
164 A1 &operator=(const A1 &Other) {
165 this->SetValue(Other.GetValue()); // A1
166 this->value = Other.value; // A1
167 // CHECK-FIXES: {{^}} this->setValue(Other.getValue()); // A1
168 // CHECK-FIXES-NEXT: {{^}} this->Value = Other.Value; // A1
169 return *this;
170 }
171 void outOfLineReset();
172};
173
174template <typename T>
175void A1<T>::outOfLineReset() {
176 this->value -= value; // A1
177 // CHECK-FIXES: {{^}} this->Value -= Value; // A1
178}
179
180template <unsigned T>
181struct A2 {
182 int value; // A2
183 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value'
184 // CHECK-FIXES: {{^}} int Value; // A2
185 A2 &operator=(const A2 &Other) {
186 value = Other.value; // A2
187 this->value = Other.value; // A2
188 // CHECK-FIXES: {{^}} Value = Other.Value; // A2
189 // CHECK-FIXES-NEXT: {{^}} this->Value = Other.Value; // A2
190 return *this;
191 }
192};
193
194// create some instances to check it works when instantiated.
195A1<int> AInt{};
196A1<int> BInt = (AInt.outOfLineReset(), AInt);
197A1<unsigned> AUnsigned{};
198A1<unsigned> BUnsigned = AUnsigned;
199} // namespace resolved_dependance
200
201namespace unresolved_dependance {
202template <typename T>
203struct DependentBase {
204 int depValue;
205 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'depValue'
206 // CHECK-FIXES: {{^}} int DepValue;
207};
208
209template <typename T>
210struct Derived : DependentBase<T> {
211 Derived &operator=(const Derived &Other) {
212 this->depValue = Other.depValue;
213 // CHECK-FIXES: {{^}} this->DepValue = Other.DepValue;
214 return *this;
215 }
216};
217
218} // namespace unresolved_dependance
219

source code of clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-member-decl-usage.cpp