1 // RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
2 // RUN: -config='{CheckOptions: [ \
3 // RUN: {key: readability-identifier-naming.MemberCase, value: CamelCase}, \
4 // RUN: {key: readability-identifier-naming.ParameterCase, value: CamelCase} \
5 // RUN: ]}' -- -fno-delayed-template-parsing
6
7 int set_up(int);
8 int clear(int);
9
10 class Foo {
11 public:
12 const int bar_baz; // comment-0
13 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for member 'bar_baz'
14 // CHECK-FIXES: {{^}} const int BarBaz; // comment-0
15
Foo(int Val)16 Foo(int Val) : bar_baz(Val) { // comment-1
17 // CHECK-FIXES: {{^}} Foo(int Val) : BarBaz(Val) { // comment-1
18 set_up(bar_baz); // comment-2
19 // CHECK-FIXES: {{^}} set_up(BarBaz); // comment-2
20 }
21
Foo()22 Foo() : Foo(0) {}
23
~Foo()24 ~Foo() {
25 clear(bar_baz); // comment-3
26 // CHECK-FIXES: {{^}} clear(BarBaz); // comment-3
27 }
28
getBar() const29 int getBar() const { return bar_baz; } // comment-4
30 // CHECK-FIXES: {{^}} int getBar() const { return BarBaz; } // comment-4
31 };
32
33 class FooBar : public Foo {
34 public:
getFancyBar() const35 int getFancyBar() const {
36 return this->bar_baz; // comment-5
37 // CHECK-FIXES: {{^}} return this->BarBaz; // comment-5
38 }
39 };
40
getBar(const Foo & Foo)41 int getBar(const Foo &Foo) {
42 return Foo.bar_baz; // comment-6
43 // CHECK-FIXES: {{^}} return Foo.BarBaz; // comment-6
44 }
45
getBar(const FooBar & Foobar)46 int getBar(const FooBar &Foobar) {
47 return Foobar.bar_baz; // comment-7
48 // CHECK-FIXES: {{^}} return Foobar.BarBaz; // comment-7
49 }
50
getFancyBar(const FooBar & Foobar)51 int getFancyBar(const FooBar &Foobar) {
52 return Foobar.getFancyBar();
53 }
54
55 template <typename Dummy>
56 class TempTest : public Foo {
57 public:
58 TempTest() = default;
TempTest(int Val)59 TempTest(int Val) : Foo(Val) {}
getBar() const60 int getBar() const { return Foo::bar_baz; } // comment-8
61 // CHECK-FIXES: {{^}} int getBar() const { return Foo::BarBaz; } // comment-8
getBar2() const62 int getBar2() const { return this->bar_baz; } // comment-9
63 // CHECK-FIXES: {{^}} int getBar2() const { return this->BarBaz; } // comment-9
64 };
65
66 TempTest<int> x; //force an instantiation
67
blah()68 int blah() {
69 return x.getBar2(); // gotta have a reference to the getBar2 so that the
70 // compiler will generate the function and resolve
71 // the DependantScopeMemberExpr
72 }
73
74 namespace Bug41122 {
75 namespace std {
76
77 // for this example we aren't bothered about how std::vector is treated
78 template <typename T> //NOLINT
79 class vector { //NOLINT
80 public:
81 void push_back(bool); //NOLINT
82 void pop_back(); //NOLINT
83 }; //NOLINT
84 }; // namespace std
85
86 class Foo {
87 std::vector<bool> &stack;
88 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for member 'stack' [readability-identifier-naming]
89 public:
Foo(std::vector<bool> & stack)90 Foo(std::vector<bool> &stack)
91 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for parameter 'stack' [readability-identifier-naming]
92 // CHECK-FIXES: {{^}} Foo(std::vector<bool> &Stack)
93 : stack(stack) {
94 // CHECK-FIXES: {{^}} : Stack(Stack) {
95 stack.push_back(true);
96 // CHECK-FIXES: {{^}} Stack.push_back(true);
97 }
~Foo()98 ~Foo() {
99 stack.pop_back();
100 // CHECK-FIXES: {{^}} Stack.pop_back();
101 }
102 };
103 }; // namespace Bug41122
104
105 namespace Bug29005 {
106 class Foo {
107 public:
108 int a_member_of_foo = 0;
109 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'a_member_of_foo'
110 // CHECK-FIXES: {{^}} int AMemberOfFoo = 0;
111 };
112
main()113 int main() {
114 Foo foo;
115 return foo.a_member_of_foo;
116 // CHECK-FIXES: {{^}} return foo.AMemberOfFoo;
117 }
118 }; // namespace Bug29005
119
120 namespace CtorInits {
121 template <typename T, unsigned N>
122 class Container {
123 T storage[N];
124 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for member 'storage'
125 // CHECK-FIXES: {{^}} T Storage[N];
126 T *pointer = &storage[0];
127 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for member 'pointer'
128 // CHECK-FIXES: {{^}} T *Pointer = &Storage[0];
129 public:
Container()130 Container() : pointer(&storage[0]) {}
131 // CHECK-FIXES: {{^}} Container() : Pointer(&Storage[0]) {}
132 };
133
foo()134 void foo() {
135 Container<int, 5> container;
136 }
137 }; // namespace CtorInits
138