1 | // RUN: %check_clang_tidy %s readability-static-definition-in-anonymous-namespace %t |
2 | |
3 | namespace { |
4 | |
5 | int a = 1; |
6 | const int b = 1; |
7 | static 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; |
10 | static const int d = 1; |
11 | // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'd' is a static definition in anonymous namespace |
12 | // CHECK-FIXES: {{^}}const int d = 1; |
13 | const static int e = 1; |
14 | // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'e' is a static definition in anonymous namespace |
15 | // CHECK-FIXES: {{^}}const int e = 1; |
16 | |
17 | void f() { |
18 | int a = 1; |
19 | static int b = 1; |
20 | } |
21 | |
22 | static int g() { |
23 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'g' is a static definition in anonymous namespace |
24 | // CHECK-FIXES: {{^}}int g() { |
25 | return 1; |
26 | } |
27 | |
28 | #define DEFINE_STATIC static |
29 | // CHECK-FIXES: {{^}}#define DEFINE_STATIC static |
30 | DEFINE_STATIC int h = 1; |
31 | // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'h' is a static definition in anonymous namespace |
32 | // CHECK-FIXES: {{^}}DEFINE_STATIC int h = 1; |
33 | |
34 | #define DEFINE_STATIC_VAR(x) static int x = 2 |
35 | // CHECK-FIXES: {{^}}#define DEFINE_STATIC_VAR(x) static int x = 2 |
36 | DEFINE_STATIC_VAR(i); |
37 | // CHECK-FIXES: {{^}}DEFINE_STATIC_VAR(i); |
38 | |
39 | namespace inner { |
40 | int a = 1; |
41 | const int b = 1; |
42 | static 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; |
45 | namespace deep_inner { |
46 | int a = 1; |
47 | const int b = 1; |
48 | static 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_inner |
52 | } // namespace inner |
53 | |
54 | template<typename T> |
55 | static 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 | |
59 | void testTemplate() { |
60 | printTemplate(5); |
61 | printTemplate(5U); |
62 | printTemplate("some string" ); |
63 | } |
64 | |
65 | } // namespace |
66 | |
67 | namespace N { |
68 | |
69 | int a = 1; |
70 | const int b = 1; |
71 | static int c = 1; |
72 | static const int d = 1; |
73 | const static int e = 1; |
74 | |
75 | } // namespace N |
76 | |