76 lines · cpp
1// RUN: %check_clang_tidy %s readability-static-definition-in-anonymous-namespace %t2 3namespace {4 5int a = 1;6const int b = 1;7static int c = 1;8// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'c' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]9// CHECK-FIXES: int c = 1;10static const int d = 1;11// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'd' is a static definition in anonymous namespace12// CHECK-FIXES: const int d = 1;13const static int e = 1;14// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'e' is a static definition in anonymous namespace15// CHECK-FIXES: const int e = 1;16 17void f() {18 int a = 1;19 static int b = 1;20}21 22static int g() {23// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'g' is a static definition in anonymous namespace24// CHECK-FIXES: int g() {25 return 1;26}27 28#define DEFINE_STATIC static29// CHECK-FIXES: #define DEFINE_STATIC static30DEFINE_STATIC int h = 1;31// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'h' is a static definition in anonymous namespace32// CHECK-FIXES: DEFINE_STATIC int h = 1;33 34#define DEFINE_STATIC_VAR(x) static int x = 235// CHECK-FIXES: #define DEFINE_STATIC_VAR(x) static int x = 236DEFINE_STATIC_VAR(i);37// CHECK-FIXES: DEFINE_STATIC_VAR(i);38 39namespace inner {40int a = 1;41const int b = 1;42static int c = 1;43// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'c' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]44// CHECK-FIXES: int c = 1;45namespace deep_inner {46int a = 1;47const int b = 1;48static int c = 1;49// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'c' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]50// CHECK-FIXES: int c = 1;51} // namespace deep_inner52} // namespace inner53 54template<typename T>55static void printTemplate(T&&) {}56// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'printTemplate' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]57// CHECK-FIXES: void printTemplate(T&&) {}58 59void testTemplate() {60 printTemplate(5);61 printTemplate(5U);62 printTemplate("some string");63}64 65} // namespace66 67namespace N {68 69int a = 1;70const int b = 1;71static int c = 1;72static const int d = 1;73const static int e = 1;74 75} // namespace N76