1 | // RUN: %check_clang_tidy %s portability-template-virtual-member-function %t |
2 | namespace UninstantiatedVirtualMember { |
3 | template<typename T> |
4 | struct 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 | |
15 | int main() { |
16 | // CHECK-MESSAGES: [[#@LINE+1]]:5: note: template instantiated here |
17 | CrossPlatformError<int>::used(); |
18 | return 0; |
19 | } |
20 | } // namespace UninstantiatedVirtualMember |
21 | |
22 | namespace UninstantiatedVirtualMembers { |
23 | template<typename T> |
24 | struct 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 | |
42 | int main() { |
43 | CrossPlatformError<int>::used(); |
44 | return 0; |
45 | } |
46 | } // namespace UninstantiatedVirtualMembers |
47 | |
48 | namespace UninstantiatedVirtualDestructor { |
49 | template<typename T> |
50 | struct 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 | |
60 | int main() { |
61 | CrossPlatformError<int>::used(); |
62 | return 0; |
63 | } |
64 | } // namespace UninstantiatedVirtualDestructor |
65 | |
66 | namespace MultipleImplicitInstantiations { |
67 | template<typename T> |
68 | struct 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 | |
80 | int main() { |
81 | CrossPlatformError<int>::used(); |
82 | CrossPlatformError<float>::used(); |
83 | CrossPlatformError<long>::used(); |
84 | return 0; |
85 | } |
86 | } // namespace MultipleImplicitInstantiations |
87 | |
88 | namespace SomeImplicitInstantiationError { |
89 | template <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 | |
99 | int main() { |
100 | CrossPlatformError<int>::used(); |
101 | CrossPlatformError<float> NoError; |
102 | return 0; |
103 | } |
104 | } // namespace SomeImplicitInstantiationError |
105 | |
106 | namespace InstantiatedVirtualMemberFunctions { |
107 | template<typename T> |
108 | struct NoError { |
109 | virtual ~NoError() {}; |
110 | virtual void unused() {}; |
111 | virtual void unused2() {}; |
112 | virtual void unused3() {}; |
113 | }; |
114 | |
115 | int main() { |
116 | NoError<int> Ne; |
117 | return 0; |
118 | } |
119 | } // namespace InstantiatedVirtualMemberFunctions |
120 | |
121 | namespace UninstantiatedNonVirtualMemberFunctions { |
122 | template<typename T> |
123 | struct NoError { |
124 | static void used() {}; |
125 | void unused() {}; |
126 | void unused2() {}; |
127 | void unused3() {}; |
128 | }; |
129 | |
130 | int main() { |
131 | NoError<int>::used(); |
132 | return 0; |
133 | } |
134 | } // namespace UninstantiatedNonVirtualMemberFunctions |
135 | |
136 | namespace PartialSpecializationError { |
137 | template<typename T, typename U> |
138 | struct CrossPlatformError {}; |
139 | |
140 | template<typename U> |
141 | struct 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 | |
153 | int main() { |
154 | CrossPlatformError<int, float>::used(); |
155 | return 0; |
156 | } |
157 | } // namespace PartialSpecializationError |
158 | |
159 | namespace PartialSpecializationNoInstantiation { |
160 | template<typename T, typename U> |
161 | struct NoInstantiation {}; |
162 | |
163 | template<typename U> |
164 | struct 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 | |