1 | // RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \ |
2 | // RUN: -config="{CheckOptions: \ |
3 | // RUN: {readability-redundant-declaration.IgnoreMacros: \ |
4 | // RUN: false}}" |
5 | // |
6 | // With -fms-compatibility and -DEXTERNINLINE, the extern inline shouldn't |
7 | // produce additional diagnostics, so same check suffix as before: |
8 | // RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \ |
9 | // RUN: -config="{CheckOptions: \ |
10 | // RUN: {readability-redundant-declaration.IgnoreMacros: \ |
11 | // RUN: false}}" -- -fms-compatibility -DEXTERNINLINE |
12 | // |
13 | // With -fno-ms-compatibility, DEXTERNINLINE causes additional output. |
14 | // (The leading ',' means "default checks in addition to NOMSCOMPAT checks.) |
15 | // RUN: %check_clang_tidy -check-suffix=,NOMSCOMPAT \ |
16 | // RUN: %s readability-redundant-declaration %t -- \ |
17 | // RUN: -config="{CheckOptions: \ |
18 | // RUN: {readability-redundant-declaration.IgnoreMacros: \ |
19 | // RUN: false}}" -- -fno-ms-compatibility -DEXTERNINLINE |
20 | |
21 | extern int Xyz; |
22 | extern int Xyz; // Xyz |
23 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Xyz' declaration [readability-redundant-declaration] |
24 | // CHECK-FIXES: {{^}}// Xyz{{$}} |
25 | int Xyz = 123; |
26 | |
27 | extern int A; |
28 | extern int A, B; |
29 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'A' declaration |
30 | // CHECK-FIXES: {{^}}extern int A, B;{{$}} |
31 | |
32 | extern int Buf[10]; |
33 | extern int Buf[10]; // Buf[10] |
34 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Buf' declaration |
35 | // CHECK-FIXES: {{^}}// Buf[10]{{$}} |
36 | |
37 | static int f(); |
38 | static int f(); // f |
39 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration |
40 | // CHECK-FIXES: {{^}}// f{{$}} |
41 | static int f() {} |
42 | |
43 | // Original check crashed for the code below. |
44 | namespace std { |
45 | typedef decltype(sizeof(0)) size_t; |
46 | } |
47 | void *operator new(std::size_t) __attribute__((__externally_visible__)); |
48 | void *operator new[](std::size_t) __attribute__((__externally_visible__)); |
49 | |
50 | // Don't warn about static member definition. |
51 | struct C { |
52 | static int I; |
53 | }; |
54 | int C::I; |
55 | |
56 | template <class T> |
57 | struct C2 { |
58 | C2(); |
59 | }; |
60 | |
61 | template <class T> |
62 | C2<T>::C2() = default; |
63 | |
64 | void best_friend(); |
65 | |
66 | struct Friendly { |
67 | friend void best_friend(); |
68 | friend void enemy(); |
69 | }; |
70 | |
71 | void enemy(); |
72 | |
73 | template <typename> |
74 | struct TemplateFriendly { |
75 | template <typename T> |
76 | friend void generic_friend(); |
77 | }; |
78 | |
79 | template <typename T> |
80 | void generic_friend() {} |
81 | |
82 | TemplateFriendly<int> template_friendly; |
83 | |
84 | template <typename> |
85 | struct TemplateFriendly2 { |
86 | template <typename T> |
87 | friend void generic_friend2() {} |
88 | }; |
89 | |
90 | template <typename T> |
91 | void generic_friend2(); |
92 | |
93 | void generic_friend_caller() { |
94 | TemplateFriendly2<int> f; |
95 | generic_friend2<int>(); |
96 | } |
97 | |
98 | |
99 | namespace macros { |
100 | #define DECLARE(x) extern int x |
101 | #define DEFINE(x) extern int x; int x = 42 |
102 | DECLARE(test); |
103 | DEFINE(test); |
104 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant 'test' declaration |
105 | // CHECK-FIXES: {{^}}#define DECLARE(x) extern int x{{$}} |
106 | // CHECK-FIXES: {{^}}#define DEFINE(x) extern int x; int x = 42{{$}} |
107 | // CHECK-FIXES: {{^}}DECLARE(test);{{$}} |
108 | // CHECK-FIXES: {{^}}DEFINE(test);{{$}} |
109 | |
110 | } // namespace macros |
111 | |
112 | inline void g() {} |
113 | |
114 | inline void g(); // g |
115 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant 'g' declaration |
116 | // CHECK-FIXES: {{^}}// g{{$}} |
117 | |
118 | #if defined(EXTERNINLINE) |
119 | extern inline void g(); // extern g |
120 | // CHECK-MESSAGES-NOMSCOMPAT: :[[@LINE-1]]:20: warning: redundant 'g' declaration |
121 | // CHECK-FIXES-NOMSCOMPAT: {{^}}// extern g{{$}} |
122 | #endif |
123 | |
124 | // PR42068 |
125 | extern "C" int externX; |
126 | int dummyBeforeBegin;extern "C" int externX;int dummyAfterEnd; |
127 | // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: redundant 'externX' declaration [readability-redundant-declaration] |
128 | // CHECK-FIXES: {{^}}int dummyBeforeBegin;int dummyAfterEnd;{{$}} |
129 | |