Haojian Wu | c253f8b | 2016-04-05 11:42:08 +0000 | [diff] [blame] | 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 |
| 40 | |
| 41 | namespace N { |
| 42 | |
| 43 | int a = 1; |
| 44 | const int b = 1; |
| 45 | static int c = 1; |
| 46 | static const int d = 1; |
| 47 | const static int e = 1; |
| 48 | |
| 49 | } // namespace N |