189a1d03eSRichard // RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
2*e8a3ddafSNathan James // RUN:   -config='{CheckOptions: { \
3*e8a3ddafSNathan James // RUN:     readability-identifier-naming.MemberCase: CamelCase, \
4*e8a3ddafSNathan James // RUN:     readability-identifier-naming.ParameterCase: CamelCase, \
5*e8a3ddafSNathan James // RUN:     readability-identifier-naming.MethodCase: camelBack, \
6*e8a3ddafSNathan James // RUN:     readability-identifier-naming.AggressiveDependentMemberLookup: true \
7*e8a3ddafSNathan James // RUN:  }}' -- -fno-delayed-template-parsing
889a1d03eSRichard 
989a1d03eSRichard int set_up(int);
1089a1d03eSRichard int clear(int);
1189a1d03eSRichard 
1289a1d03eSRichard class Foo {
1389a1d03eSRichard public:
1489a1d03eSRichard   const int bar_baz; // comment-0
1589a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for member 'bar_baz'
1689a1d03eSRichard   // CHECK-FIXES: {{^}}  const int BarBaz; // comment-0
1789a1d03eSRichard 
Foo(int Val)1889a1d03eSRichard   Foo(int Val) : bar_baz(Val) { // comment-1
1989a1d03eSRichard     // CHECK-FIXES: {{^}}  Foo(int Val) : BarBaz(Val) { // comment-1
2089a1d03eSRichard     set_up(bar_baz); // comment-2
2189a1d03eSRichard     // CHECK-FIXES: {{^}}    set_up(BarBaz); // comment-2
2289a1d03eSRichard   }
2389a1d03eSRichard 
Foo()2489a1d03eSRichard   Foo() : Foo(0) {}
2589a1d03eSRichard 
~Foo()2689a1d03eSRichard   ~Foo() {
2789a1d03eSRichard     clear(bar_baz); // comment-3
2889a1d03eSRichard     // CHECK-FIXES: {{^}}    clear(BarBaz); // comment-3
2989a1d03eSRichard   }
3089a1d03eSRichard 
getBar() const3189a1d03eSRichard   int getBar() const { return bar_baz; } // comment-4
3289a1d03eSRichard   // CHECK-FIXES: {{^}}  int getBar() const { return BarBaz; } // comment-4
3389a1d03eSRichard };
3489a1d03eSRichard 
3589a1d03eSRichard class FooBar : public Foo {
3689a1d03eSRichard public:
getFancyBar() const3789a1d03eSRichard   int getFancyBar() const {
3889a1d03eSRichard     return this->bar_baz; // comment-5
3989a1d03eSRichard     // CHECK-FIXES: {{^}}    return this->BarBaz; // comment-5
4089a1d03eSRichard   }
4189a1d03eSRichard };
4289a1d03eSRichard 
getBar(const Foo & Foo)4389a1d03eSRichard int getBar(const Foo &Foo) {
4489a1d03eSRichard   return Foo.bar_baz; // comment-6
4589a1d03eSRichard   // CHECK-FIXES: {{^}}  return Foo.BarBaz; // comment-6
4689a1d03eSRichard }
4789a1d03eSRichard 
getBar(const FooBar & Foobar)4889a1d03eSRichard int getBar(const FooBar &Foobar) {
4989a1d03eSRichard   return Foobar.bar_baz; // comment-7
5089a1d03eSRichard   // CHECK-FIXES: {{^}}  return Foobar.BarBaz; // comment-7
5189a1d03eSRichard }
5289a1d03eSRichard 
getFancyBar(const FooBar & Foobar)5389a1d03eSRichard int getFancyBar(const FooBar &Foobar) {
5489a1d03eSRichard   return Foobar.getFancyBar();
5589a1d03eSRichard }
5689a1d03eSRichard 
5789a1d03eSRichard template <typename Dummy>
5889a1d03eSRichard class TempTest : public Foo {
5989a1d03eSRichard public:
6089a1d03eSRichard   TempTest() = default;
TempTest(int Val)6189a1d03eSRichard   TempTest(int Val) : Foo(Val) {}
getBar() const6289a1d03eSRichard   int getBar() const { return Foo::bar_baz; } // comment-8
6389a1d03eSRichard   // CHECK-FIXES: {{^}}  int getBar() const { return Foo::BarBaz; } // comment-8
getBar2() const6489a1d03eSRichard   int getBar2() const { return this->bar_baz; } // comment-9
6589a1d03eSRichard   // CHECK-FIXES: {{^}}  int getBar2() const { return this->BarBaz; } // comment-9
6689a1d03eSRichard };
6789a1d03eSRichard 
6889a1d03eSRichard namespace Bug41122 {
6989a1d03eSRichard namespace std {
7089a1d03eSRichard 
7189a1d03eSRichard // for this example we aren't bothered about how std::vector is treated
7289a1d03eSRichard template <typename T>   // NOLINT
7389a1d03eSRichard struct vector {         // NOLINT
7489a1d03eSRichard   void push_back(bool); // NOLINT
7589a1d03eSRichard   void pop_back();      // NOLINT
7689a1d03eSRichard };                      // NOLINT
7789a1d03eSRichard };                      // namespace std
7889a1d03eSRichard 
7989a1d03eSRichard class Foo {
8089a1d03eSRichard   std::vector<bool> &stack;
8189a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for member 'stack' [readability-identifier-naming]
8289a1d03eSRichard public:
Foo(std::vector<bool> & stack)8389a1d03eSRichard   Foo(std::vector<bool> &stack)
8489a1d03eSRichard       // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for parameter 'stack' [readability-identifier-naming]
8589a1d03eSRichard       // CHECK-FIXES: {{^}}  Foo(std::vector<bool> &Stack)
8689a1d03eSRichard       : stack(stack) {
8789a1d03eSRichard     // CHECK-FIXES: {{^}}      : Stack(Stack) {
8889a1d03eSRichard     stack.push_back(true);
8989a1d03eSRichard     // CHECK-FIXES: {{^}}    Stack.push_back(true);
9089a1d03eSRichard   }
~Foo()9189a1d03eSRichard   ~Foo() {
9289a1d03eSRichard     stack.pop_back();
9389a1d03eSRichard     // CHECK-FIXES: {{^}}    Stack.pop_back();
9489a1d03eSRichard   }
9589a1d03eSRichard };
9689a1d03eSRichard }; // namespace Bug41122
9789a1d03eSRichard 
9889a1d03eSRichard namespace Bug29005 {
9989a1d03eSRichard class Foo {
10089a1d03eSRichard public:
10189a1d03eSRichard   int a_member_of_foo = 0;
10289a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'a_member_of_foo'
10389a1d03eSRichard   // CHECK-FIXES: {{^}}  int AMemberOfFoo = 0;
10489a1d03eSRichard };
10589a1d03eSRichard 
main()10689a1d03eSRichard int main() {
10789a1d03eSRichard   Foo foo;
10889a1d03eSRichard   return foo.a_member_of_foo;
10989a1d03eSRichard   // CHECK-FIXES: {{^}}  return foo.AMemberOfFoo;
11089a1d03eSRichard }
11189a1d03eSRichard }; // namespace Bug29005
11289a1d03eSRichard 
11389a1d03eSRichard namespace CtorInits {
11489a1d03eSRichard template <typename T, unsigned N>
11589a1d03eSRichard class Container {
11689a1d03eSRichard   T storage[N];
11789a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for member 'storage'
11889a1d03eSRichard   // CHECK-FIXES: {{^}}  T Storage[N];
11989a1d03eSRichard   T *pointer = &storage[0];
12089a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for member 'pointer'
12189a1d03eSRichard   // CHECK-FIXES: {{^}}  T *Pointer = &Storage[0];
12289a1d03eSRichard public:
Container()12389a1d03eSRichard   Container() : pointer(&storage[0]) {}
12489a1d03eSRichard   // CHECK-FIXES: {{^}}  Container() : Pointer(&Storage[0]) {}
12589a1d03eSRichard };
12689a1d03eSRichard 
foo()12789a1d03eSRichard void foo() {
12889a1d03eSRichard   Container<int, 5> container;
12989a1d03eSRichard }
13089a1d03eSRichard } // namespace CtorInits
13189a1d03eSRichard 
13289a1d03eSRichard namespace resolved_dependance {
13389a1d03eSRichard template <typename T>
13489a1d03eSRichard struct A0 {
13589a1d03eSRichard   int value;
13689a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value'
operator =resolved_dependance::A013789a1d03eSRichard   A0 &operator=(const A0 &Other) {
13889a1d03eSRichard     value = Other.value;       // A0
13989a1d03eSRichard     this->value = Other.value; // A0
14089a1d03eSRichard     // CHECK-FIXES:      {{^}}    Value = Other.Value;       // A0
14189a1d03eSRichard     // CHECK-FIXES-NEXT: {{^}}    this->Value = Other.Value; // A0
14289a1d03eSRichard     return *this;
14389a1d03eSRichard   }
14489a1d03eSRichard   void outOfLineReset();
14589a1d03eSRichard };
14689a1d03eSRichard 
14789a1d03eSRichard template <typename T>
outOfLineReset()14889a1d03eSRichard void A0<T>::outOfLineReset() {
14989a1d03eSRichard   this->value -= value; // A0
15089a1d03eSRichard   // CHECK-FIXES: {{^}}  this->Value -= Value; // A0
15189a1d03eSRichard }
15289a1d03eSRichard 
15389a1d03eSRichard template <typename T>
15489a1d03eSRichard struct A1 {
15589a1d03eSRichard   int value; // A1
15689a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value'
15789a1d03eSRichard   // CHECK-FIXES: {{^}}  int Value; // A1
GetValueresolved_dependance::A115889a1d03eSRichard   int GetValue() const { return value; } // A1
15989a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for method 'GetValue'
16089a1d03eSRichard   // CHECK-FIXES {{^}}  int getValue() const { return Value; } // A1
SetValueresolved_dependance::A116189a1d03eSRichard   void SetValue(int Value) { this->value = Value; } // A1
16289a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 'SetValue'
16389a1d03eSRichard   // CHECK-FIXES {{^}}  void setValue(int Value) { this->Value = Value; } // A1
operator =resolved_dependance::A116489a1d03eSRichard   A1 &operator=(const A1 &Other) {
16589a1d03eSRichard     this->SetValue(Other.GetValue()); // A1
16689a1d03eSRichard     this->value = Other.value;        // A1
16789a1d03eSRichard     // CHECK-FIXES:      {{^}}    this->setValue(Other.getValue()); // A1
16889a1d03eSRichard     // CHECK-FIXES-NEXT: {{^}}    this->Value = Other.Value;        // A1
16989a1d03eSRichard     return *this;
17089a1d03eSRichard   }
17189a1d03eSRichard   void outOfLineReset();
17289a1d03eSRichard };
17389a1d03eSRichard 
17489a1d03eSRichard template <typename T>
outOfLineReset()17589a1d03eSRichard void A1<T>::outOfLineReset() {
17689a1d03eSRichard   this->value -= value; // A1
17789a1d03eSRichard   // CHECK-FIXES: {{^}}  this->Value -= Value; // A1
17889a1d03eSRichard }
17989a1d03eSRichard 
18089a1d03eSRichard template <unsigned T>
18189a1d03eSRichard struct A2 {
18289a1d03eSRichard   int value; // A2
18389a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value'
18489a1d03eSRichard   // CHECK-FIXES: {{^}}  int Value; // A2
operator =resolved_dependance::A218589a1d03eSRichard   A2 &operator=(const A2 &Other) {
18689a1d03eSRichard     value = Other.value;       // A2
18789a1d03eSRichard     this->value = Other.value; // A2
18889a1d03eSRichard     // CHECK-FIXES:      {{^}}    Value = Other.Value;       // A2
18989a1d03eSRichard     // CHECK-FIXES-NEXT: {{^}}    this->Value = Other.Value; // A2
19089a1d03eSRichard     return *this;
19189a1d03eSRichard   }
19289a1d03eSRichard };
19389a1d03eSRichard 
19489a1d03eSRichard // create some instances to check it works when instantiated.
19589a1d03eSRichard A1<int> AInt{};
19689a1d03eSRichard A1<int> BInt = (AInt.outOfLineReset(), AInt);
19789a1d03eSRichard A1<unsigned> AUnsigned{};
19889a1d03eSRichard A1<unsigned> BUnsigned = AUnsigned;
19989a1d03eSRichard } // namespace resolved_dependance
20089a1d03eSRichard 
20189a1d03eSRichard namespace unresolved_dependance {
20289a1d03eSRichard template <typename T>
20389a1d03eSRichard struct DependentBase {
20489a1d03eSRichard   int depValue;
20589a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'depValue'
20689a1d03eSRichard   // CHECK-FIXES:  {{^}}  int DepValue;
20789a1d03eSRichard };
20889a1d03eSRichard 
20989a1d03eSRichard template <typename T>
21089a1d03eSRichard struct Derived : DependentBase<T> {
operator =unresolved_dependance::Derived21189a1d03eSRichard   Derived &operator=(const Derived &Other) {
21289a1d03eSRichard     this->depValue = Other.depValue;
21389a1d03eSRichard     // CHECK-FIXES: {{^}}    this->DepValue = Other.DepValue;
21489a1d03eSRichard     return *this;
21589a1d03eSRichard   }
21689a1d03eSRichard };
21789a1d03eSRichard 
21889a1d03eSRichard } // namespace unresolved_dependance
219