1 // RUN: %check_clang_tidy %s misc-confusable-identifiers %t 2 3 int fo; 4 int o; 5 // CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'o' is confusable with 'fo' [misc-confusable-identifiers] 6 // CHECK-MESSAGES: :[[#@LINE-3]]:5: note: other declaration found here 7 8 void no() { 9 int oo; 10 } 11 12 void worry() { 13 int foo; 14 } 15 int i; 16 int fi; 17 // CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'fi' is confusable with 'i' [misc-confusable-identifiers] 18 // CHECK-MESSAGES: :[[#@LINE-3]]:5: note: other declaration found here 19 20 bool f0(const char *q1, const char *ql) { 21 // CHECK-MESSAGES: :[[#@LINE-1]]:37: warning: 'ql' is confusable with 'q1' [misc-confusable-identifiers] 22 // CHECK-MESSAGES: :[[#@LINE-2]]:21: note: other declaration found here 23 return q1 < ql; 24 } 25 26 // should not print anything 27 namespace ns { 28 struct Foo {}; 29 } // namespace ns 30 auto f = ns::Foo(); 31 32 struct Test { 33 void f1(const char *pl); 34 }; 35 36 bool f2(const char *p1, const char *ql) { 37 return p1 < ql; 38 } 39 40 bool f3(const char *q0, const char *q1) { 41 return q0 < q1; 42 } 43 44 template <typename i1> 45 struct S { 46 template <typename il> 47 void f4() {} 48 // CHECK-MESSAGES: :[[#@LINE-2]]:22: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers] 49 // CHECK-MESSAGES: :[[#@LINE-5]]:20: note: other declaration found here 50 }; 51 52 template <typename i1> 53 void f5(int il) { 54 // CHECK-MESSAGES: :[[#@LINE-1]]:13: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers] 55 // CHECK-MESSAGES: :[[#@LINE-3]]:20: note: other declaration found here 56 } 57 58 template <typename O0> 59 void f6() { 60 int OO = 0; 61 // CHECK-MESSAGES: :[[#@LINE-1]]:7: warning: 'OO' is confusable with 'O0' [misc-confusable-identifiers] 62 // CHECK-MESSAGES: :[[#@LINE-4]]:20: note: other declaration found here 63 } 64 int OO = 0; // no warning, not same scope as f6 65 66 namespace f7 { 67 int i1; 68 } 69 70 namespace f8 { 71 int il; // no warning, different namespace 72 } 73 74 namespace f7 { 75 int il; 76 // CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers] 77 // CHECK-MESSAGES: :[[#@LINE-10]]:5: note: other declaration found here 78 } // namespace f7 79 80 template <typename t1, typename tl> 81 // CHECK-MESSAGES: :[[#@LINE-1]]:33: warning: 'tl' is confusable with 't1' [misc-confusable-identifiers] 82 // CHECK-MESSAGES: :[[#@LINE-2]]:20: note: other declaration found here 83 void f9(); 84 85 struct Base0 { 86 virtual void mO0(); 87 88 private: 89 void mII(); 90 }; 91 92 struct Derived0 : Base0 { 93 void mOO(); 94 // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'mOO' is confusable with 'mO0' [misc-confusable-identifiers] 95 // CHECK-MESSAGES: :[[#@LINE-9]]:16: note: other declaration found here 96 97 void mI1(); // no warning: mII is private 98 }; 99 100 struct Base1 { 101 long mO0; 102 103 private: 104 long mII; 105 }; 106 107 struct Derived1 : Base1 { 108 long mOO; 109 // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'mOO' is confusable with 'mO0' [misc-confusable-identifiers] 110 // CHECK-MESSAGES: :[[#@LINE-9]]:8: note: other declaration found here 111 112 long mI1(); // no warning: mII is private 113 }; 114