1 // RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \
2 // RUN:   -config="{CheckOptions: \
3 // RUN:             [{key: readability-redundant-declaration.IgnoreMacros, \
4 // RUN:               value: 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:             [{key: readability-redundant-declaration.IgnoreMacros, \
11 // RUN:               value: 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:             [{key: readability-redundant-declaration.IgnoreMacros, \
19 // RUN:               value: 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{{$}}
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 namespace macros {
74 #define DECLARE(x) extern int x
75 #define DEFINE(x) extern int x; int x = 42
76 DECLARE(test);
77 DEFINE(test);
78 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant 'test' declaration
79 // CHECK-FIXES: {{^}}#define DECLARE(x) extern int x{{$}}
80 // CHECK-FIXES: {{^}}#define DEFINE(x) extern int x; int x = 42{{$}}
81 // CHECK-FIXES: {{^}}DECLARE(test);{{$}}
82 // CHECK-FIXES: {{^}}DEFINE(test);{{$}}
83 
84 } // namespace macros
85 
g()86 inline void g() {}
87 
88 inline void g(); // g
89 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant 'g' declaration
90 // CHECK-FIXES: {{^}}// g{{$}}
91 
92 #if defined(EXTERNINLINE)
93 extern inline void g(); // extern g
94 // CHECK-MESSAGES-NOMSCOMPAT: :[[@LINE-1]]:20: warning: redundant 'g' declaration
95 // CHECK-FIXES-NOMSCOMPAT: {{^}}// extern g{{$}}
96 #endif
97