xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp (revision f89fa238faa6a63168997a8a1d03c15b71da8080)
1 // RUN: %check_clang_tidy %s misc-use-internal-linkage %t -- -- -I%S/Inputs/use-internal-linkage
2 // RUN: %check_clang_tidy %s misc-use-internal-linkage %t -- \
3 // RUN:   -config="{CheckOptions: {misc-use-internal-linkage.FixMode: 'UseStatic'}}"  -- -I%S/Inputs/use-internal-linkage
4 
5 #include "func.h"
6 
7 void func() {}
8 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func'
9 // CHECK-FIXES: static void func() {}
10 
11 template<class T>
12 void func_template() {}
13 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_template'
14 // CHECK-FIXES: static void func_template() {}
15 
16 void func_cpp_inc() {}
17 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc'
18 // CHECK-FIXES: static void func_cpp_inc() {}
19 
20 int* func_cpp_inc_return_ptr() {}
21 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc_return_ptr'
22 // CHECK-FIXES: static int* func_cpp_inc_return_ptr() {}
23 
24 const int* func_cpp_inc_return_const_ptr() {}
25 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: function 'func_cpp_inc_return_const_ptr'
26 // CHECK-FIXES: static const int* func_cpp_inc_return_const_ptr() {}
27 
28 int const* func_cpp_inc_return_ptr_const() {}
29 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: function 'func_cpp_inc_return_ptr_const'
30 // CHECK-FIXES: static int const* func_cpp_inc_return_ptr_const() {}
31 
32 int * const func_cpp_inc_return_const() {}
33 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'func_cpp_inc_return_const'
34 // CHECK-FIXES: static int * const func_cpp_inc_return_const() {}
35 
36 volatile const int* func_cpp_inc_return_volatile_const_ptr() {}
37 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: function 'func_cpp_inc_return_volatile_const_ptr'
38 // CHECK-FIXES: static volatile const int* func_cpp_inc_return_volatile_const_ptr() {}
39 
40 [[nodiscard]] void func_nodiscard() {}
41 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: function 'func_nodiscard'
42 // CHECK-FIXES: {{\[\[nodiscard\]\]}} static void func_nodiscard() {}
43 
44 #define NDS [[nodiscard]]
45 #define NNDS
46 
47 NDS void func_nds() {}
48 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: function 'func_nds'
49 // CHECK-FIXES: NDS static void func_nds() {}
50 
51 NNDS void func_nnds() {}
52 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: function 'func_nnds'
53 // CHECK-FIXES: NNDS static void func_nnds() {}
54 
55 #include "func_cpp.inc"
56 
57 void func_h_inc() {}
58 
59 struct S {
60   void method();
61 };
62 void S::method() {}
63 
64 void func_header() {}
65 extern void func_extern() {}
66 static void func_static() {}
67 namespace {
68 void func_anonymous_ns() {}
69 } // namespace
70 
71 int main(int argc, const char*argv[]) {}
72 
73 extern "C" {
74 void func_extern_c_1() {}
75 }
76 
77 extern "C" void func_extern_c_2() {}
78 
79 namespace gh117488 {
80 void func_with_body();
81 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_with_body'
82 // CHECK-FIXES: static void func_with_body();
83 void func_with_body() {}
84 
85 void func_without_body();
86 void func_without_body();
87 }
88 
89 // gh117489 start
90 namespace std {
91 using size_t = decltype(sizeof(int));
92 }
93 void * operator new(std::size_t) { return nullptr; }
94 void * operator new[](std::size_t) { return nullptr; }
95 void operator delete(void*) noexcept {}
96 void operator delete[](void*) noexcept {}
97 // gh117489 end
98