1// RUN: %check_clang_tidy %s portability-template-virtual-member-function %t
2namespace UninstantiatedVirtualMember {
3template<typename T>
4struct CrossPlatformError {
5 virtual ~CrossPlatformError() = default;
6
7 static void used() {}
8
9 // CHECK-MESSAGES: [[#@LINE+1]]:18: warning: unspecified virtual member function instantiation
10 virtual void unused() {
11 T MSVCError = this;
12 };
13};
14
15int main() {
16 // CHECK-MESSAGES: [[#@LINE+1]]:5: note: template instantiated here
17 CrossPlatformError<int>::used();
18 return 0;
19}
20} // namespace UninstantiatedVirtualMember
21
22namespace UninstantiatedVirtualMembers {
23template<typename T>
24struct CrossPlatformError {
25 virtual ~CrossPlatformError() = default;
26
27 static void used() {}
28
29 // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation
30 // CHECK-MESSAGES: [[#@LINE+13]]:5: note: template instantiated here
31 virtual void unused() {
32 T MSVCError = this;
33 };
34
35 // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation
36 // CHECK-MESSAGES: [[#@LINE+7]]:5: note: template instantiated here
37 virtual void unused2() {
38 T MSVCError = this;
39 };
40};
41
42int main() {
43 CrossPlatformError<int>::used();
44 return 0;
45}
46} // namespace UninstantiatedVirtualMembers
47
48namespace UninstantiatedVirtualDestructor {
49template<typename T>
50struct CrossPlatformError {
51 // CHECK-MESSAGES: [[#@LINE+2]]:13: warning: unspecified virtual member function instantiation
52 // CHECK-MESSAGES: [[#@LINE+9]]:5: note: template instantiated here
53 virtual ~CrossPlatformError() {
54 T MSVCError = this;
55 };
56
57 static void used() {}
58};
59
60int main() {
61 CrossPlatformError<int>::used();
62 return 0;
63}
64} // namespace UninstantiatedVirtualDestructor
65
66namespace MultipleImplicitInstantiations {
67template<typename T>
68struct CrossPlatformError {
69 virtual ~CrossPlatformError() = default;
70
71 static void used() {}
72
73 // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation
74 // CHECK-MESSAGES: [[#@LINE+7]]:5: note: template instantiated here
75 virtual void unused() {
76 T MSVCError = this;
77 };
78};
79
80int main() {
81 CrossPlatformError<int>::used();
82 CrossPlatformError<float>::used();
83 CrossPlatformError<long>::used();
84 return 0;
85}
86} // namespace MultipleImplicitInstantiations
87
88namespace SomeImplicitInstantiationError {
89template <typename T> struct CrossPlatformError {
90 virtual ~CrossPlatformError() = default;
91
92 static void used() {}
93
94 // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation
95 // CHECK-MESSAGES: [[#@LINE+5]]:5: note: template instantiated here
96 virtual void unused(){};
97};
98
99int main() {
100 CrossPlatformError<int>::used();
101 CrossPlatformError<float> NoError;
102 return 0;
103}
104} // namespace SomeImplicitInstantiationError
105
106namespace InstantiatedVirtualMemberFunctions {
107template<typename T>
108struct NoError {
109 virtual ~NoError() {};
110 virtual void unused() {};
111 virtual void unused2() {};
112 virtual void unused3() {};
113};
114
115int main() {
116 NoError<int> Ne;
117 return 0;
118}
119} // namespace InstantiatedVirtualMemberFunctions
120
121namespace UninstantiatedNonVirtualMemberFunctions {
122template<typename T>
123struct NoError {
124 static void used() {};
125 void unused() {};
126 void unused2() {};
127 void unused3() {};
128};
129
130int main() {
131 NoError<int>::used();
132 return 0;
133}
134} // namespace UninstantiatedNonVirtualMemberFunctions
135
136namespace PartialSpecializationError {
137template<typename T, typename U>
138struct CrossPlatformError {};
139
140template<typename U>
141struct CrossPlatformError<int, U>{
142 virtual ~CrossPlatformError() = default;
143
144 static void used() {}
145
146 // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation
147 // CHECK-MESSAGES: [[#@LINE+7]]:5: note: template instantiated here
148 virtual void unused() {
149 U MSVCError = this;
150 };
151};
152
153int main() {
154 CrossPlatformError<int, float>::used();
155 return 0;
156}
157} // namespace PartialSpecializationError
158
159namespace PartialSpecializationNoInstantiation {
160template<typename T, typename U>
161struct NoInstantiation {};
162
163template<typename U>
164struct NoInstantiation<int, U>{
165 virtual ~NoInstantiation() = default;
166
167 static void used() {}
168
169 virtual void unused() {
170 U MSVCError = this;
171 };
172};
173} // namespace PartialSpecializationNoInstantiation
174

source code of clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp