xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp (revision 3897d3cf71efa50da755e2fc3514b6c2bd4f1433)
189a1d03eSRichard // RUN: %check_clang_tidy %s misc-confusable-identifiers %t
289a1d03eSRichard 
3*3897d3cfSserge-sans-paille int l0;
4*3897d3cfSserge-sans-paille int lO;
5*3897d3cfSserge-sans-paille // CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'lO' is confusable with 'l0' [misc-confusable-identifiers]
67a550212Sserge-sans-paille // CHECK-MESSAGES: :[[#@LINE-3]]:5: note: other declaration found here
789a1d03eSRichard 
no()889a1d03eSRichard void no() {
989a1d03eSRichard   int ��oo;
1089a1d03eSRichard }
1189a1d03eSRichard 
worry()1289a1d03eSRichard void worry() {
1389a1d03eSRichard   int foo;
1489a1d03eSRichard }
15*3897d3cfSserge-sans-paille int l1;
16*3897d3cfSserge-sans-paille int ll;
17*3897d3cfSserge-sans-paille // CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'll' is confusable with 'l1' [misc-confusable-identifiers]
187a550212Sserge-sans-paille // CHECK-MESSAGES: :[[#@LINE-3]]:5: note: other declaration found here
197a550212Sserge-sans-paille 
f0(const char * q1,const char * ql)207a550212Sserge-sans-paille bool f0(const char *q1, const char *ql) {
217a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-1]]:37: warning: 'ql' is confusable with 'q1' [misc-confusable-identifiers]
227a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-2]]:21: note: other declaration found here
237a550212Sserge-sans-paille   return q1 < ql;
247a550212Sserge-sans-paille }
2589a1d03eSRichard 
2689a1d03eSRichard // should not print anything
2789a1d03eSRichard namespace ns {
2889a1d03eSRichard struct Foo {};
2989a1d03eSRichard } // namespace ns
3089a1d03eSRichard auto f = ns::Foo();
317a550212Sserge-sans-paille 
327a550212Sserge-sans-paille struct Test {
337a550212Sserge-sans-paille   void f1(const char *pl);
347a550212Sserge-sans-paille };
357a550212Sserge-sans-paille 
f2(const char * p1,const char * ql)367a550212Sserge-sans-paille bool f2(const char *p1, const char *ql) {
377a550212Sserge-sans-paille   return p1 < ql;
387a550212Sserge-sans-paille }
397a550212Sserge-sans-paille 
f3(const char * q0,const char * q1)407a550212Sserge-sans-paille bool f3(const char *q0, const char *q1) {
417a550212Sserge-sans-paille   return q0 < q1;
427a550212Sserge-sans-paille }
437a550212Sserge-sans-paille 
447a550212Sserge-sans-paille template <typename i1>
457a550212Sserge-sans-paille struct S {
467a550212Sserge-sans-paille   template <typename il>
f4S477a550212Sserge-sans-paille   void f4() {}
487a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-2]]:22: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers]
497a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-5]]:20: note: other declaration found here
507a550212Sserge-sans-paille };
517a550212Sserge-sans-paille 
527a550212Sserge-sans-paille template <typename i1>
f5(int il)537a550212Sserge-sans-paille void f5(int il) {
547a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-1]]:13: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers]
557a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-3]]:20: note: other declaration found here
567a550212Sserge-sans-paille }
577a550212Sserge-sans-paille 
587a550212Sserge-sans-paille namespace f7 {
597a550212Sserge-sans-paille int i1;
607a550212Sserge-sans-paille }
617a550212Sserge-sans-paille 
627a550212Sserge-sans-paille namespace f8 {
637a550212Sserge-sans-paille int il; // no warning, different namespace
647a550212Sserge-sans-paille }
657a550212Sserge-sans-paille 
667a550212Sserge-sans-paille namespace f7 {
677a550212Sserge-sans-paille int il;
687a550212Sserge-sans-paille // CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: 'il' is confusable with 'i1' [misc-confusable-identifiers]
697a550212Sserge-sans-paille // CHECK-MESSAGES: :[[#@LINE-10]]:5: note: other declaration found here
707a550212Sserge-sans-paille } // namespace f7
717a550212Sserge-sans-paille 
727a550212Sserge-sans-paille template <typename t1, typename tl>
737a550212Sserge-sans-paille // CHECK-MESSAGES: :[[#@LINE-1]]:33: warning: 'tl' is confusable with 't1' [misc-confusable-identifiers]
747a550212Sserge-sans-paille // CHECK-MESSAGES: :[[#@LINE-2]]:20: note: other declaration found here
757a550212Sserge-sans-paille void f9();
767a550212Sserge-sans-paille 
777a550212Sserge-sans-paille struct Base0 {
787a550212Sserge-sans-paille   virtual void mO0();
797a550212Sserge-sans-paille 
807a550212Sserge-sans-paille private:
817a550212Sserge-sans-paille   void mII();
827a550212Sserge-sans-paille };
837a550212Sserge-sans-paille 
847a550212Sserge-sans-paille struct Derived0 : Base0 {
857a550212Sserge-sans-paille   void mOO();
867a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'mOO' is confusable with 'mO0' [misc-confusable-identifiers]
877a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-9]]:16: note: other declaration found here
887a550212Sserge-sans-paille 
897a550212Sserge-sans-paille   void mI1(); // no warning: mII is private
907a550212Sserge-sans-paille };
917a550212Sserge-sans-paille 
927a550212Sserge-sans-paille struct Base1 {
937a550212Sserge-sans-paille   long mO0;
947a550212Sserge-sans-paille 
957a550212Sserge-sans-paille private:
967a550212Sserge-sans-paille   long mII;
977a550212Sserge-sans-paille };
987a550212Sserge-sans-paille 
997a550212Sserge-sans-paille struct Derived1 : Base1 {
1007a550212Sserge-sans-paille   long mOO;
1017a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-1]]:8: warning: 'mOO' is confusable with 'mO0' [misc-confusable-identifiers]
1027a550212Sserge-sans-paille   // CHECK-MESSAGES: :[[#@LINE-9]]:8: note: other declaration found here
1037a550212Sserge-sans-paille 
1047a550212Sserge-sans-paille   long mI1(); // no warning: mII is private
1057a550212Sserge-sans-paille };
106