1 | // RUN: %check_clang_tidy %s readability-qualified-auto %t -- -- -std=c++20 |
2 | namespace std { |
3 | template <typename T> |
4 | class vector { // dummy impl |
5 | T _data[1]; |
6 | |
7 | public: |
8 | T *begin() { return _data; } |
9 | const T *begin() const { return _data; } |
10 | T *end() { return &_data[1]; } |
11 | const T *end() const { return &_data[1]; } |
12 | unsigned size() const { return 0; } |
13 | }; |
14 | } // namespace std |
15 | |
16 | std::vector<int> *getVec(); |
17 | const std::vector<int> *getCVec(); |
18 | void foo() { |
19 | if (auto X = getVec(); X->size() > 0) { |
20 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'auto X' can be declared as 'auto *X' |
21 | // CHECK-FIXES: {{^}} if (auto *X = getVec(); X->size() > 0) { |
22 | } |
23 | switch (auto X = getVec(); X->size()) { |
24 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'auto X' can be declared as 'auto *X' |
25 | // CHECK-FIXES: {{^}} switch (auto *X = getVec(); X->size()) { |
26 | default: |
27 | break; |
28 | } |
29 | for (auto X = getVec(); auto Xi : *X) { |
30 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'auto X' can be declared as 'auto *X' |
31 | // CHECK-FIXES: {{^}} for (auto *X = getVec(); auto Xi : *X) { |
32 | } |
33 | } |
34 | void bar() { |
35 | if (auto X = getCVec(); X->size() > 0) { |
36 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'auto X' can be declared as 'const auto *X' |
37 | // CHECK-FIXES: {{^}} if (const auto *X = getCVec(); X->size() > 0) { |
38 | } |
39 | switch (auto X = getCVec(); X->size()) { |
40 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'auto X' can be declared as 'const auto *X' |
41 | // CHECK-FIXES: {{^}} switch (const auto *X = getCVec(); X->size()) { |
42 | default: |
43 | break; |
44 | } |
45 | for (auto X = getCVec(); auto Xi : *X) { |
46 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'auto X' can be declared as 'const auto *X' |
47 | // CHECK-FIXES: {{^}} for (const auto *X = getCVec(); auto Xi : *X) { |
48 | } |
49 | } |
50 | |