1
- // RUN: %check_clang_tidy %s readability-qualified-auto %t
1
+ // RUN: %check_clang_tidy %s readability-qualified-auto %t \
2
+ // RUN: -config='{CheckOptions: { \
3
+ // RUN: readability-qualified-auto.AllowedTypes: "[iI]terator$;my::ns::Ignored1;std::array<.*>::Ignored2;MyIgnoredPtr" \
4
+ // RUN: }}'
2
5
3
6
namespace typedefs {
4
7
typedef int *MyPtr;
@@ -238,3 +241,145 @@ void baz() {
238
241
239
242
auto &MyFunctionRef2 = *getPtrFunction ();
240
243
}
244
+
245
+ namespace std {
246
+
247
+ template <typename T, int N>
248
+ struct array {
249
+ typedef T value_type;
250
+
251
+ typedef value_type* iterator;
252
+ typedef value_type* Iterator;
253
+ using using_iterator = T*;
254
+ typedef const value_type* const_iterator;
255
+ typedef const value_type* constIterator;
256
+
257
+ struct Ignored2 {};
258
+ using NotIgnored2 = Ignored2;
259
+
260
+ iterator begin () { return nullptr ; }
261
+ const_iterator begin () const { return nullptr ; }
262
+ iterator end () { return nullptr ; }
263
+ const_iterator end () const { return nullptr ; }
264
+ };
265
+
266
+ struct Iterator {};
267
+
268
+ struct Ignored2 {}; // should not be ignored
269
+
270
+ } // namespace std
271
+
272
+ typedef std::Iterator iterator;
273
+
274
+ namespace my {
275
+ namespace ns {
276
+
277
+ struct Ignored1 {};
278
+
279
+ using NotIgnored1 = Ignored1;
280
+ typedef Ignored1 NotIgnored2;
281
+
282
+ } // namespace ns
283
+
284
+ struct Ignored1 {}; // should not be ignored
285
+
286
+ } // namespace my
287
+
288
+ typedef int *MyIgnoredPtr;
289
+ MyIgnoredPtr getIgnoredPtr ();
290
+
291
+ void ignored_types () {
292
+ auto ignored_ptr = getIgnoredPtr ();
293
+ // CHECK-MESSAGES-NOT: warning: 'auto ignored_ptr' can be declared as 'auto *ignored_ptr'
294
+ // CHECK-FIXES-NOT: auto *ignored_ptr = getIgnoredPtr();
295
+
296
+ std::array<int , 4 > arr;
297
+ std::array<int , 4 > carr;
298
+
299
+ auto it1 = arr.begin ();
300
+ // CHECK-MESSAGES-NOT: warning: 'auto it' can be declared as 'auto *it'
301
+ // CHECK-FIXES-NOT: auto *it = vec.it_begin();
302
+
303
+ auto it2 = carr.begin ();
304
+ // CHECK-MESSAGES-NOT: warning: 'auto it2' can be declared as 'auto *it2'
305
+ // CHECK-FIXES-NOT: auto *it2 = carr.begin();
306
+
307
+ auto it3 = std::array<int , 4 >::iterator{};
308
+ // CHECK-MESSAGES-NOT: warning: 'auto it3' can be declared as 'auto *it3'
309
+ // CHECK-FIXES-NOT: auto *it3 = std::array<int, 4>::iterator{};
310
+
311
+ auto it4 = std::array<int , 4 >::Iterator{};
312
+ // CHECK-MESSAGES-NOT: warning: 'auto it4' can be declared as 'auto *it4'
313
+ // CHECK-FIXES-NOT: auto *it4 = std::array<int, 4>::Iterator{};
314
+
315
+ auto it5 = std::array<int , 4 >::using_iterator{};
316
+ // CHECK-MESSAGES-NOT: warning: 'auto it5' can be declared as 'auto *it5'
317
+ // CHECK-FIXES-NOT: auto *it5 = std::array<int, 4>::using_iterator{};
318
+
319
+ auto it6 = std::array<int , 4 >::const_iterator{};
320
+ // CHECK-MESSAGES-NOT: warning: 'auto it6' can be declared as 'auto *it6'
321
+ // CHECK-FIXES-NOT: auto *it6 = std::array<int, 4>::const_iterator{};
322
+
323
+ auto it7 = std::array<int , 4 >::constIterator{};
324
+ // CHECK-MESSAGES-NOT: warning: 'auto it7' can be declared as 'auto *it7'
325
+ // CHECK-FIXES-NOT: auto *it7 = std::array<int, 4>::constIterator{};
326
+
327
+ auto it8 = new std::Iterator ();
328
+ // CHECK-MESSAGES-NOT: warning: 'auto it8' can be declared as 'auto *it8'
329
+ // CHECK-FIXES-NOT: auto *it8 = new std::Iterator();
330
+
331
+ auto it9 = new iterator ();
332
+ // CHECK-MESSAGES-NOT: warning: 'auto it9' can be declared as 'auto *it9'
333
+ // CHECK-FIXES-NOT: auto *it9 = new iterator();
334
+
335
+ auto arr_ignored2 = new std::array<int , 4 >::Ignored2 ();
336
+ // CHECK-MESSAGES-NOT: warning: 'auto arr_ignored2' can be declared as 'auto *arr_ignored2'
337
+ // CHECK-FIXES-NOT: auto *arr_ignored2 = new std::array<int, 4>::Ignored2();
338
+
339
+ auto arr_not_ignored2 = new std::array<int , 4 >::NotIgnored2 ();
340
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto arr_not_ignored2' can be declared as 'auto *arr_not_ignored2'
341
+ // CHECK-FIXES: auto *arr_not_ignored2 = new std::array<int, 4>::NotIgnored2();
342
+
343
+ auto not_ignored2 = new std::Ignored2 ();
344
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto not_ignored2' can be declared as 'auto *not_ignored2'
345
+ // CHECK-FIXES: auto *not_ignored2 = new std::Ignored2();
346
+
347
+ auto ignored1 = new my::ns::Ignored1 ();
348
+ // CHECK-MESSAGES-NOT: warning: 'auto ignored1' can be declared as 'auto *ignored1'
349
+ // CHECK-FIXES-NOT: auto *ignored1 = new my::ns::Ignored1();
350
+
351
+ auto not_ignored1 = new my::ns::NotIgnored1 ();
352
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto not_ignored1' can be declared as 'auto *not_ignored1'
353
+ // CHECK-FIXES: auto *not_ignored1 = new my::ns::NotIgnored1();
354
+
355
+ auto not2_ignored1 = new my::ns::NotIgnored2 ();
356
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto not2_ignored1' can be declared as 'auto *not2_ignored1'
357
+ // CHECK-FIXES: auto *not2_ignored1 = new my::ns::NotIgnored2();
358
+
359
+ auto not3_ignored1 = new my::Ignored1 ();
360
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto not3_ignored1' can be declared as 'auto *not3_ignored1'
361
+ // CHECK-FIXES: auto *not3_ignored1 = new my::Ignored1();
362
+ }
363
+
364
+ template <typename T>
365
+ void ignored_types_template (std::array<T, 4 > arr, const std::array<T, 4 >& carr) {
366
+ auto it1 = arr.begin ();
367
+ // CHECK-MESSAGES-NOT: warning: 'auto it' can be declared as 'auto *it'
368
+ // CHECK-FIXES-NOT: auto *it = arr.it_begin();
369
+
370
+ auto it2 = carr.begin ();
371
+ // CHECK-MESSAGES-NOT: warning: 'auto it2' can be declared as 'auto *it2'
372
+ // CHECK-FIXES-NOT: auto *it2 = carr.begin();
373
+
374
+ for (auto Data : arr) {
375
+ // CHECK-MESSAGES-NOT: warning: 'auto Data' can be declared as 'auto *Data'
376
+ // CHECK-FIXES-NOT: {{^}} for (auto *Data : MClassTemplate) {
377
+ change (*Data);
378
+ }
379
+
380
+ for (auto Data : carr) {
381
+ // CHECK-MESSAGES-NOT: warning: 'auto Data' can be declared as 'const auto *Data'
382
+ // CHECK-FIXES-NOT: {{^}} for (const auto *Data : MClassTemplate) {
383
+ change (*Data);
384
+ }
385
+ }
0 commit comments