You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-static-over-anonymous-namespace-allow-member-functions.cpp
Copy file name to clipboardExpand all lines: clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-static-over-anonymous-namespace-allow-variables.cpp
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'regularFunction' is declared in an anonymous namespace; prefer using 'static' for restricting visibility [llvm-prefer-static-over-anonymous-namespace]
7
15
16
+
int Variable = 42;
17
+
auto Lambda = []() { return42; };
18
+
staticint StaticVariable = 42;
19
+
}
20
+
8
21
voiddeclaredFunction();
9
22
10
23
staticvoidstaticFunction() {}
11
24
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: place static function 'staticFunction' outside of an anonymous namespace
12
25
13
26
int globalVariable = 42;
27
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:5: warning: variable 'globalVariable' is declared in an anonymous namespace;
14
28
15
29
staticint staticVariable = 42;
30
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:12: warning: place static variable 'staticVariable' outside of an anonymous namespace
31
+
32
+
typedefint MyInt;
33
+
const MyInt myGlobalVariable = 42;
34
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:13: warning: variable 'myGlobalVariable' is declared in an anonymous namespace;
35
+
36
+
template<typename T>
37
+
constexpr T Pi = T(3.1415926);
38
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:13: warning: variable 'Pi' is declared in an anonymous namespace;
39
+
40
+
void (*funcPtr)() = nullptr;
41
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:8: warning: variable 'funcPtr' is declared in an anonymous namespace;
42
+
43
+
auto lambda = []() { return42; };
44
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:6: warning: variable 'lambda' is declared in an anonymous namespace;
45
+
46
+
classInstanceClass {
47
+
int member;
48
+
};
49
+
50
+
InstanceClass instance;
51
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:15: warning: variable 'instance' is declared in an anonymous namespace;
52
+
53
+
InstanceClass* instancePtr = nullptr;
54
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:16: warning: variable 'instancePtr' is declared in an anonymous namespace;
55
+
56
+
InstanceClass& instanceRef = instance;
57
+
// CHECK-MESSAGES-VAR: :[[@LINE-1]]:16: warning: variable 'instanceRef' is declared in an anonymous namespace;
16
58
17
59
classMyClass {
18
60
public:
19
61
MyClass();
20
62
MyClass(const MyClass&) {}
63
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:3: warning: place definition of method 'MyClass' outside of an anonymous namespace
21
64
MyClass(MyClass&&) = default;
65
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:3: warning: place definition of method 'MyClass' outside of an anonymous namespace
22
66
MyClass& operator=(const MyClass&);
23
67
MyClass& operator=(MyClass&&);
24
68
booloperator<(const MyClass&) const;
25
69
voidmemberFunction();
26
70
staticvoidstaticMemberFunction();
27
71
voidmemberDefinedInClass() {}
72
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:8: warning: place definition of method 'memberDefinedInClass' outside of an anonymous namespace
28
73
staticvoidstaticMemberDefinedInClass() {}
74
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:15: warning: place definition of method 'staticMemberDefinedInClass' outside of an anonymous namespace
75
+
template <typename T>
76
+
voidtemplateFunction();
77
+
template <typename T>
78
+
voidtemplateFunctionInClass() {}
79
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:8: warning: place definition of method 'templateFunctionInClass' outside of an anonymous namespace
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: place definition of method 'staticMemberFunction' outside of an anonymous namespace
48
99
100
+
template <typename T>
101
+
voidMyClass::templateFunction() {}
102
+
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: place definition of method 'templateFunction' outside of an anonymous namespace
103
+
49
104
template<typename T>
50
105
voidtemplateFunction(T Value) {}
51
-
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'templateFunction' is declared in an anonymous namespace;
106
+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'templateFunction' is declared in an anonymous namespace; prefer using 'static' for restricting visibility
52
107
53
108
template<>
54
109
void templateFunction<int>(int Value) {}
55
-
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'templateFunction<int>' is declared in an anonymous namespace;
110
+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'templateFunction<int>' is declared in an anonymous namespace; prefer using 'static' for restricting visibility
56
111
57
112
template<typename T>
58
113
classTemplateClass {
59
114
public:
60
115
TemplateClass();
61
116
TemplateClass(const TemplateClass&) {}
117
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:3: warning: place definition of method 'TemplateClass<T>' outside of an anonymous namespace
62
118
TemplateClass(TemplateClass&&) = default;
119
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:3: warning: place definition of method 'TemplateClass<T>' outside of an anonymous namespace
63
120
TemplateClass& operator=(const TemplateClass&);
64
121
TemplateClass& operator=(TemplateClass&&);
65
122
booloperator<(const TemplateClass&) const;
66
123
voidmemberFunc();
67
124
T getValue() const;
68
125
voidmemberDefinedInClass() {}
126
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:8: warning: place definition of method 'memberDefinedInClass' outside of an anonymous namespace
69
127
staticvoidstaticMemberDefinedInClass() {}
128
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:15: warning: place definition of method 'staticMemberDefinedInClass' outside of an anonymous namespace
129
+
template <typename U>
130
+
voidtemplateMethodInTemplateClass() {}
131
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:8: warning: place definition of method 'templateMethodInTemplateClass' outside of an anonymous namespace
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: place definition of method 'getValue' outside of an anonymous namespace
97
159
98
160
inlinevoidinlineFunction() {}
99
-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'inlineFunction' is declared in an anonymous namespace;
161
+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'inlineFunction' is declared in an anonymous namespace; prefer using 'static' for restricting visibility
100
162
101
163
autoautoReturnFunction() -> int { return42; }
102
-
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'autoReturnFunction' is declared in an anonymous namespace;
164
+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'autoReturnFunction' is declared in an anonymous namespace; prefer using 'static' for restricting visibility
103
165
104
166
classOuterClass {
105
167
public:
106
168
classNestedClass {
107
169
public:
108
170
voidnestedMemberFunc();
171
+
voidnestedMemberDefinedInClass() {}
172
+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:10: warning: place definition of method 'nestedMemberDefinedInClass' outside of an anonymous namespace
0 commit comments