brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.4 KiB · 61c3aeb Raw
219 lines · cpp
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-parsing8 9int set_up(int);10int clear(int);11 12class Foo {13public:14  const int bar_baz; // comment-015  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for member 'bar_baz'16  // CHECK-FIXES: const int BarBaz; // comment-017 18  Foo(int Val) : bar_baz(Val) { // comment-119    // CHECK-FIXES: Foo(int Val) : BarBaz(Val) { // comment-120    set_up(bar_baz); // comment-221    // CHECK-FIXES: set_up(BarBaz); // comment-222  }23 24  Foo() : Foo(0) {}25 26  ~Foo() {27    clear(bar_baz); // comment-328    // CHECK-FIXES: clear(BarBaz); // comment-329  }30 31  int getBar() const { return bar_baz; } // comment-432  // CHECK-FIXES: int getBar() const { return BarBaz; } // comment-433};34 35class FooBar : public Foo {36public:37  int getFancyBar() const {38    return this->bar_baz; // comment-539    // CHECK-FIXES: return this->BarBaz; // comment-540  }41};42 43int getBar(const Foo &Foo) {44  return Foo.bar_baz; // comment-645  // CHECK-FIXES: return Foo.BarBaz; // comment-646}47 48int getBar(const FooBar &Foobar) {49  return Foobar.bar_baz; // comment-750  // CHECK-FIXES: return Foobar.BarBaz; // comment-751}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-863  // CHECK-FIXES: int getBar() const { return Foo::BarBaz; } // comment-864  int getBar2() const { return this->bar_baz; } // comment-965  // CHECK-FIXES: int getBar2() const { return this->BarBaz; } // comment-966};67 68namespace Bug41122 {69namespace std {70 71// for this example we aren't bothered about how std::vector is treated72template <typename T>   // NOLINT73struct vector {         // NOLINT74  void push_back(bool); // NOLINT75  void pop_back();      // NOLINT76};                      // NOLINT77};                      // namespace std78 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 Bug4112297 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 Bug29005112 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 CtorInits131 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;       // A0139    this->value = Other.value; // A0140    // CHECK-FIXES:      Value = Other.Value;       // A0141    // CHECK-FIXES-NEXT: this->Value = Other.Value; // A0142    return *this;143  }144  void outOfLineReset();145};146 147template <typename T>148void A0<T>::outOfLineReset() {149  this->value -= value; // A0150  // CHECK-FIXES: this->Value -= Value; // A0151}152 153template <typename T>154struct A1 {155  int value; // A1156  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value'157  // CHECK-FIXES: int Value; // A1158  int GetValue() const { return value; } // A1159  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for method 'GetValue'160  // CHECK-FIXES {{^}}  int getValue() const { return Value; } // A1161  void SetValue(int Value) { this->value = Value; } // A1162  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 'SetValue'163  // CHECK-FIXES {{^}}  void setValue(int Value) { this->Value = Value; } // A1164  A1 &operator=(const A1 &Other) {165    this->SetValue(Other.GetValue()); // A1166    this->value = Other.value;        // A1167    // CHECK-FIXES:      this->setValue(Other.getValue()); // A1168    // CHECK-FIXES-NEXT: this->Value = Other.Value;        // A1169    return *this;170  }171  void outOfLineReset();172};173 174template <typename T>175void A1<T>::outOfLineReset() {176  this->value -= value; // A1177  // CHECK-FIXES: this->Value -= Value; // A1178}179 180template <unsigned T>181struct A2 {182  int value; // A2183  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for member 'value'184  // CHECK-FIXES: int Value; // A2185  A2 &operator=(const A2 &Other) {186    value = Other.value;       // A2187    this->value = Other.value; // A2188    // CHECK-FIXES:      Value = Other.Value;       // A2189    // CHECK-FIXES-NEXT: this->Value = Other.Value; // A2190    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_dependance200 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_dependance219