bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / test / redundantcast.cxx
blobbe34a57729c6320c1dcd83087e40bf230a06c5b5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <cstddef>
12 #include "redundantcast.hxx"
14 void f1(char *) {}
15 void f2(char const *) {}
17 struct D: S {};
19 enum Enum1 { X };
21 void testConstCast() {
22 char * p1;
23 char const * p2;
24 p1 = nullptr;
25 p2 = "";
26 f1(const_cast<char *>(p1)); // expected-error {{redundant const_cast from 'char *' lvalue to 'char *' prvalue [loplugin:redundantcast]}}
27 f1(const_cast<char * const>(p1)); // expected-error {{redundant const_cast from 'char *' lvalue to 'char *const' prvalue [loplugin:redundantcast]}}
28 f1(const_cast<char *>(p2));
29 f1(const_cast<char * const>(p2));
30 f2(const_cast<char *>(p1)); // expected-error {{redundant const_cast from 'char *' lvalue to 'char *' prvalue [loplugin:redundantcast]}}
31 f2(const_cast<char * const>(p1)); // expected-error {{redundant const_cast from 'char *' lvalue to 'char *const' prvalue [loplugin:redundantcast]}}
32 f2(const_cast<char const *>(p1));
33 f2(const_cast<char const * const>(p1));
34 f2(const_cast<char *>(p2)); // expected-error {{redundant const_cast from 'const char *' to 'char *', result is implicitly cast to 'const char *' [loplugin:redundantcast]}}
35 f2(const_cast<char * const>(p2)); // expected-error {{redundant const_cast from 'const char *' to 'char *', result is implicitly cast to 'const char *' [loplugin:redundantcast]}}
36 f2(const_cast<char const *>(p2)); // expected-error {{redundant const_cast from 'const char *' lvalue to 'const char *' prvalue [loplugin:redundantcast]}}
37 f2(const_cast<char const * const>(p2)); // expected-error {{redundant const_cast from 'const char *' lvalue to 'const char *const' prvalue [loplugin:redundantcast]}}
39 void * vp = nullptr;
40 (void) const_cast<char *>(static_cast<char const *>(vp)); // expected-error {{redundant static_cast/const_cast combination from 'void *' via 'const char *' to 'char *' [loplugin:redundantcast]}}
41 (void) const_cast<char *>(static_cast<char const *>(nullptr)); // expected-error {{redundant static_cast/const_cast combination from 'nullptr_t' via 'const char *' to 'char *' [loplugin:redundantcast]}}
42 (void) const_cast<S &>(static_cast<S const &>(D{})); // expected-error {{redundant static_cast/const_cast combination from 'D' via 'const S &' to 'S &' [loplugin:redundantcast]}}
44 S const s{};
45 const_cast<S &>(s).f1();
46 const_cast<S &>(s).f2(); // expected-error {{redundant const_cast from 'const S' to 'S', result is implicitly cast to 'const S' [loplugin:redundantcast]}}
47 const_cast<S &>(s).f3();
48 s.f3();
50 // non-class lvalue, non-const:
51 int ni{};
52 // (void) const_cast<int>(ni);
53 (void) const_cast<int &>(ni); // expected-error {{redundant const_cast from 'int' lvalue to 'int &' lvalue [loplugin:redundantcast]}}
54 (void) const_cast<int &&>(ni);
55 // (void) const_cast<int const>(ni);
56 (void) const_cast<int const &>(ni);
57 (void) const_cast<int const &&>(ni);
59 // non-class lvalue, const:
60 int const ci{};
61 // (void) const_cast<int>(ci);
62 (void) const_cast<int &>(ci);
63 (void) const_cast<int &&>(ci);
64 // (void) const_cast<int const>(ci);
65 (void) const_cast<int const &>(ci); // expected-error {{redundant const_cast from 'const int' lvalue to 'const int &' lvalue [loplugin:redundantcast]}}
66 (void) const_cast<int const &&>(ci);
68 // non-class xvalue, non-const:
69 // (void) const_cast<int>(nix());
70 // (void) const_cast<int &>(nix());
71 (void) const_cast<int &&>(nix()); // expected-error {{redundant const_cast from 'int' xvalue to 'int &&' xvalue [loplugin:redundantcast]}}
72 // (void) const_cast<int const>(nix());
73 // (void) const_cast<int const &>(nix());
74 (void) const_cast<int const &&>(nix());
76 // non-class xvalue, const:
77 // (void) const_cast<int>(cix());
78 // (void) const_cast<int &>(cix());
79 (void) const_cast<int &&>(cix());
80 // (void) const_cast<int const>(cix());
81 // (void) const_cast<int const &>(cix());
82 (void) const_cast<int const &&>(cix()); // expected-error {{redundant const_cast from 'const int' xvalue to 'const int &&' xvalue [loplugin:redundantcast]}}
84 // non-class prvalue, non-const:
85 // (void) const_cast<int>(nir());
86 // (void) const_cast<int &>(nir());
87 // (void) const_cast<int &&>(nir());
88 // (void) const_cast<int const>(nir());
89 // (void) const_cast<int const &>(nir());
90 // (void) const_cast<int const &&>(nir());
92 // non-class prvalue, const:
93 // (void) const_cast<int>(cir());
94 // (void) const_cast<int &>(cir());
95 // (void) const_cast<int &&>(cir());
96 // (void) const_cast<int const>(cir());
97 // (void) const_cast<int const &>(cir());
98 // (void) const_cast<int const &&>(cir());
100 // class lvalue, non-const:
101 S ns{};
102 // (void) const_cast<S>(ns);
103 (void) const_cast<S &>(ns); // expected-error {{redundant const_cast from 'S' lvalue to 'S &' lvalue [loplugin:redundantcast]}}
104 (void) const_cast<S &&>(ns);
105 // (void) const_cast<S const>(ns);
106 (void) const_cast<S const &>(ns);
107 (void) const_cast<S const &&>(ns);
109 // class lvalue, const:
110 S const cs{};
111 // (void) const_cast<S>(cs);
112 (void) const_cast<S &>(cs);
113 (void) const_cast<S &&>(cs);
114 // (void) const_cast<S const>(cs);
115 (void) const_cast<S const &>(cs); // expected-error {{redundant const_cast from 'const S' lvalue to 'const S &' lvalue [loplugin:redundantcast]}}
116 (void) const_cast<S const &&>(cs);
118 // class xvalue, non-const:
119 // (void) const_cast<S>(nsx());
120 // (void) const_cast<S &>(nsx());
121 (void) const_cast<S &&>(nsx()); // expected-error {{redundant const_cast from 'S' xvalue to 'S &&' xvalue [loplugin:redundantcast]}}
122 // (void) const_cast<S const>(nsx());
123 // (void) const_cast<S const &>(nsx());
124 (void) const_cast<S const &&>(nsx());
126 // class xvalue, const:
127 // (void) const_cast<S>(csx());
128 // (void) const_cast<S &>(csx());
129 (void) const_cast<S &&>(csx());
130 // (void) const_cast<S const>(csx());
131 // (void) const_cast<S const &>(csx());
132 (void) const_cast<S const &&>(csx()); // expected-error {{redundant const_cast from 'const S' xvalue to 'const S &&' xvalue [loplugin:redundantcast]}}
134 // class prvalue, non-const:
135 // (void) const_cast<S>(nsr());
136 // (void) const_cast<S &>(nsr());
137 (void) const_cast<S &&>(nsr());
138 // (void) const_cast<S const>(nsr());
139 // (void) const_cast<S const &>(nsr());
140 (void) const_cast<S const &&>(nsr());
142 // class prvalue, const:
143 // (void) const_cast<S>(csr());
144 // (void) const_cast<S &>(csr());
145 (void) const_cast<S &&>(csr());
146 // (void) const_cast<S const>(csr());
147 // (void) const_cast<S const &>(csr());
148 (void) const_cast<S const &&>(csr());
151 void testStaticCast() {
152 // non-class lvalue, non-const:
153 int ni{};
154 (void) static_cast<int>(ni); // expected-error {{static_cast from 'int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
155 /* => */ (void) int(ni);
156 (void) static_cast<int &>(ni); // expected-error {{static_cast from 'int' lvalue to 'int &' lvalue is redundant [loplugin:redundantcast]}}
157 (void) static_cast<int &&>(ni);
158 (void) static_cast<int const>(ni); // expected-error {{in static_cast from 'int' lvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
159 /* => */ (void) static_cast<int>(ni); // expected-error {{static_cast from 'int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
160 /* => */ (void) int(ni);
161 (void) static_cast<int const &>(ni); // expected-error {{static_cast from 'int' lvalue to 'const int &' lvalue should be written as const_cast [loplugin:redundantcast]}}
162 /* => */ (void) const_cast<int const &>(ni);
163 (void) static_cast<int const &&>(ni); // expected-error {{static_cast from 'int' lvalue to 'const int &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
164 /* => */ (void) const_cast<int const &&>(ni);
166 // non-class lvalue, const:
167 int const ci{};
168 (void) static_cast<int>(ci); // expected-error {{static_cast from 'const int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
169 /* => */ (void) int(ci);
170 // (void) static_cast<int &>(ci);
171 // (void) static_cast<int &&>(ci);
172 (void) static_cast<int const>(ci); // expected-error {{in static_cast from 'const int' lvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
173 /* => */ (void) static_cast<int>(ci); // expected-error {{static_cast from 'const int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
174 /* => */ (void) int(ci);
175 (void) static_cast<int const &>(ci); // expected-error {{static_cast from 'const int' lvalue to 'const int &' lvalue is redundant [loplugin:redundantcast]}}
176 (void) static_cast<int const &&>(ci);
178 // non-class xvalue, non-const:
179 (void) static_cast<int>(nix()); // expected-error {{static_cast from 'int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
180 /* => */ (void) int(nix());
181 // (void) static_cast<int &>(nix());
182 (void) static_cast<int &&>(nix()); // expected-error {{static_cast from 'int' xvalue to 'int &&' xvalue is redundant [loplugin:redundantcast]}}
183 (void) static_cast<int const>(nix()); // expected-error {{in static_cast from 'int' xvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
184 /* => */ (void) static_cast<int>(nix()); // expected-error {{static_cast from 'int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
185 (void) static_cast<int const &>(nix());
186 (void) static_cast<int const &&>(nix()); // expected-error {{static_cast from 'int' xvalue to 'const int &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
187 /* => */ (void) const_cast<int const &&>(nix());
189 // non-class xvalue, const:
190 (void) static_cast<int>(cix()); // expected-error {{static_cast from 'const int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
191 /* => */ (void) int(cix());
192 // (void) static_cast<int &>(cix());
193 // (void) static_cast<int &&>(cix());
194 (void) static_cast<int const>(cix()); // expected-error {{in static_cast from 'const int' xvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
195 /* => */ (void) static_cast<int>(cix()); // expected-error {{static_cast from 'const int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
196 /* => */ (void) int(cix());
197 (void) static_cast<int const &>(cix());
198 (void) static_cast<int const &&>(cix()); // expected-error {{static_cast from 'const int' xvalue to 'const int &&' xvalue is redundant [loplugin:redundantcast]}}
200 // non-class prvalue, non-const:
201 (void) static_cast<int>(nir()); // expected-error {{static_cast from 'int' prvalue to 'int' prvalue is redundant [loplugin:redundantcast]}}
202 // (void) static_cast<int &>(nir());
203 (void) static_cast<int &&>(nir());
204 (void) static_cast<int const>(nir()); // expected-error {{in static_cast from 'int' prvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
205 /* => */ (void) static_cast<int>(nir()); // expected-error {{static_cast from 'int' prvalue to 'int' prvalue is redundant [loplugin:redundantcast]}}
206 (void) static_cast<int const &>(nir()); // expected-error {{static_cast from 'int' prvalue to 'const int &' lvalue is redundant [loplugin:redundantcast]}}
207 (void) static_cast<int const &&>(nir());
209 // non-class prvalue, const:
210 (void) static_cast<int>(cir()); // expected-error {{static_cast from 'int' prvalue to 'int' prvalue is redundant [loplugin:redundantcast]}}
211 // (void) static_cast<int &>(cir());
212 (void) static_cast<int &&>(cir());
213 (void) static_cast<int const>(cir()); // expected-error {{in static_cast from 'int' prvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
214 /* => */ (void) static_cast<int>(cir()); // expected-error {{static_cast from 'int' prvalue to 'int' prvalue is redundant [loplugin:redundantcast]}}
215 (void) static_cast<int const &>(cir()); // expected-error {{static_cast from 'int' prvalue to 'const int &' lvalue is redundant [loplugin:redundantcast]}}
216 (void) static_cast<int const &&>(cir());
218 // class lvalue, non-const:
219 S ns{};
220 (void) static_cast<S>(ns); // expected-error {{static_cast from 'S' lvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
221 /* => */ (void) S(ns);
222 (void) static_cast<S &>(ns); // expected-error {{static_cast from 'S' lvalue to 'S &' lvalue is redundant [loplugin:redundantcast]}}
223 (void) static_cast<S &&>(ns);
224 (void) static_cast<S const>(ns); // expected-error {{static_cast from 'S' lvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
225 /* => */ using CS = const S; (void) CS(ns);
226 (void) static_cast<S const &>(ns); // expected-error {{static_cast from 'S' lvalue to 'const S &' lvalue should be written as const_cast [loplugin:redundantcast]}}
227 /* => */ (void) const_cast<S const &>(ns);
228 (void) static_cast<S const &&>(ns); // expected-error {{static_cast from 'S' lvalue to 'const S &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
229 /* => */ (void) const_cast<S const &&>(ns);
231 // class lvalue, const:
232 S const cs{};
233 (void) static_cast<S>(cs); // expected-error {{static_cast from 'const S' lvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
234 /* => */ (void) S(cs);
235 // (void) static_cast<S &>(cs);
236 // (void) static_cast<S &&>(cs);
237 (void) static_cast<S const>(cs); // expected-error {{static_cast from 'const S' lvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
238 /* => */ (void) CS(cs);
239 (void) static_cast<S const &>(cs); // expected-error {{static_cast from 'const S' lvalue to 'const S &' lvalue is redundant [loplugin:redundantcast]}}
240 (void) static_cast<S const &&>(cs);
242 // class xvalue, non-const:
243 (void) static_cast<S>(nsx()); // expected-error {{static_cast from 'S' xvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
244 /* => */ (void) S(nsx());
245 // (void) static_cast<S &>(nsx());
246 (void) static_cast<S &&>(nsx()); // expected-error {{static_cast from 'S' xvalue to 'S &&' xvalue is redundant [loplugin:redundantcast]}}
247 (void) static_cast<S const>(nsx()); // expected-error {{static_cast from 'S' xvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
248 /* => */ (void) CS(nsx());
249 (void) static_cast<S const &>(nsx());
250 (void) static_cast<S const &&>(nsx()); // expected-error {{static_cast from 'S' xvalue to 'const S &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
251 /* => */ (void) const_cast<S const &&>(nsx());
253 // class xvalue, const:
254 (void) static_cast<S>(csx()); // expected-error {{static_cast from 'const S' xvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
255 /* => */ (void) S(csx());
256 // (void) static_cast<S &>(csx());
257 // (void) static_cast<S &&>(csx());
258 (void) static_cast<S const>(csx()); // expected-error {{static_cast from 'const S' xvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
259 /* => */ (void) CS(csx());
260 (void) static_cast<S const &>(csx());
261 (void) static_cast<S const &&>(csx()); // expected-error {{static_cast from 'const S' xvalue to 'const S &&' xvalue is redundant [loplugin:redundantcast]}}
263 // class prvalue, non-const:
264 (void) static_cast<S>(nsr()); // expected-error {{static_cast from 'S' prvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
265 /* => */ (void) S(nsr());
266 // (void) static_cast<S &>(nsr());
267 (void) static_cast<S &&>(nsr());
268 (void) static_cast<S const>(nsr()); // expected-error {{static_cast from 'S' prvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
269 /* => */ (void) CS(nsr());
270 (void) static_cast<S const &>(nsr()); // expected-error {{static_cast from 'S' prvalue to 'const S &' lvalue is redundant [loplugin:redundantcast]}}
271 (void) static_cast<S const &&>(nsr()); // expected-error {{static_cast from 'S' prvalue to 'const S &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
272 /* => */ (void) const_cast<S const &&>(nsr());
274 // class prvalue, const:
275 (void) static_cast<S>(csr()); // expected-error {{static_cast from 'const S' prvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
276 /* => */ (void) S(csr());
277 // (void) static_cast<S &>(csr());
278 // (void) static_cast<S &&>(csr());
279 (void) static_cast<S const>(csr()); // expected-error {{static_cast from 'const S' prvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
280 /* => */ (void) CS(csr());
281 (void) static_cast<S const &>(csr()); // expected-error {{static_cast from 'const S' prvalue to 'const S &' lvalue is redundant [loplugin:redundantcast]}}
282 (void) static_cast<S const &&>(csr());
285 void testFunctionalCast() {
286 (void) int(nir()); // expected-error {{redundant functional cast from 'int' to 'int' [loplugin:redundantcast]}}
287 (void) S(nsr());
290 void testCStyleCast() {
291 Enum1 e = (Enum1)Enum1::X; // expected-error {{redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]}}
292 (void)e;
295 template<typename T>
296 struct EnumItemInterface {
297 T GetValue() { return static_cast<T>(0); }
299 class Enum1Item : public EnumItemInterface<Enum1> {
301 bool testCStyleCastOfTemplateMethodResult(Enum1Item* item) {
302 return (Enum1)item->GetValue() == Enum1::X; // expected-error {{redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]}}
305 using T1 = int;
306 T1 nt1r() { return 0; }
307 void testArithmeticTypedefs() {
308 (void) static_cast<T1>(nir());
309 (void) T1(nir());
310 (void) (T1) nir();
311 (void) static_cast<int>(nt1r());
312 (void) int(nt1r());
313 (void) (int) nt1r();
314 using T2 = T1;
315 (void) static_cast<T2>(nt1r());
316 (void) T2(nt1r());
317 (void) (T2) nt1r();
318 (void) static_cast<T1>(nt1r()); // expected-error {{redundant}}
319 (void) T1(nt1r()); // expected-error {{redundant}}
320 (void) (T1) nt1r(); // expected-error {{redundant}}
322 T1 const c{};
323 (void) static_cast<T1>(c); // expected-error {{redundant}}
326 void testReinterpretConstCast() {
327 int n = 0;
328 (void) reinterpret_cast<std::size_t>((const_cast<int const *>(&n))); // expected-error-re {{redundant const_cast from 'int *' to 'const int *' within reinterpret_cast to fundamental type 'std::size_t' (aka 'unsigned {{.+}}') [loplugin:redundantcast]}}
331 void testDynamicCast() {
333 struct S1 { virtual ~S1(); };
334 struct S2 final: S1 {};
335 struct S3: S1 {};
337 S1 * s1 = nullptr;
338 S2 * s2 = nullptr;
340 (void) dynamic_cast<S2 *>(s1);
341 (void) dynamic_cast<S1 *>(s2);
342 (void) dynamic_cast<S2 *>(s2); // expected-error {{redundant dynamic cast from 'S2 *' to 'S2 *' [loplugin:redundantcast]}}
343 (void) dynamic_cast<S3 *>(s2);
346 void overload(int);
347 void overload(long);
348 void nonOverload();
350 struct Overload {
351 int overload();
352 long overload() const;
353 void nonOverload();
356 void testOverloadResolution() {
357 (void) static_cast<void (*)(long)>(overload);
358 (void) static_cast<void (*)(long)>((overload));
359 (void) static_cast<void (*)(long)>(&overload);
360 (void) static_cast<void (*)(long)>((&overload));
361 (void) static_cast<void (*)(long)>(&((overload)));
362 (void) static_cast<void (*)()>(nonOverload); // expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
363 (void) static_cast<void (*)()>((nonOverload)); // expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
364 (void) static_cast<void (*)()>(&nonOverload); // expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
365 (void) static_cast<void (*)()>((&nonOverload)); // expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
366 (void) static_cast<void (*)()>(&((nonOverload))); // expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
367 (void) static_cast<long (Overload::*)() const>(&Overload::overload);
368 (void) static_cast<void (Overload::*)()>(&Overload::nonOverload); // expected-error {{static_cast from 'void (Overload::*)()' prvalue to 'void (Overload::*)()' prvalue is redundant [loplugin:redundantcast]}}
370 using OverloadFn = void (*)(long);
371 (void) OverloadFn(overload);
372 using NonOverloadFn = void (*)();
373 (void) NonOverloadFn(nonOverload); // expected-error {{redundant functional cast from 'void (*)()' to 'NonOverloadFn' (aka 'void (*)()') [loplugin:redundantcast]}}
374 using OverloadMemFn = long (Overload::*)() const;
375 (void) OverloadMemFn(&Overload::overload);
376 using NonOverloadMemFn = void (Overload::*)();
377 (void) NonOverloadMemFn(&Overload::nonOverload); // expected-error {{redundant functional cast from 'void (Overload::*)()' to 'NonOverloadMemFn' (aka 'void (Overload::*)()') [loplugin:redundantcast]}}
380 void testIntermediaryStaticCast() {
381 int n = 0;
382 n = static_cast<double>(n); // expected-error {{suspicious static_cast from 'int' to 'double', result is implicitly cast to 'int' [loplugin:redundantcast]}}
383 n = double(n); // expected-error {{suspicious functional cast from 'int' to 'double', result is implicitly cast to 'int' [loplugin:redundantcast]}}
384 double d = 0.0;
385 d = static_cast<int>(d) + 1.0; // expected-error {{suspicious static_cast from 'double' to 'int', result is implicitly cast to 'double' [loplugin:redundantcast]}}
386 d = int(d) + 1.0; // expected-error {{suspicious functional cast from 'double' to 'int', result is implicitly cast to 'double' [loplugin:redundantcast]}}
389 void testArrayDecay() {
390 (void) static_cast<char const *>(""); // expected-error {{redundant static_cast from 'const char [1]' to 'const char *' [loplugin:redundantcast]}}
391 (void) reinterpret_cast<char const *>(""); // expected-error {{redundant reinterpret_cast from 'const char [1]' to 'const char *' [loplugin:redundantcast]}}
392 (void) reinterpret_cast<char const *>(u8"");
395 int main() {
396 testConstCast();
397 testStaticCast();
398 testFunctionalCast();
399 testCStyleCast();
400 testCStyleCastOfTemplateMethodResult(nullptr);
401 testReinterpretConstCast();
402 testDynamicCast();
403 testIntermediaryStaticCast();
404 testArrayDecay();
407 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */