[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
Helmut Januschka via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 20 13:01:24 PST 2024
hjanuschka wrote:
feedback addressed, you were right about the template case, it is really broken, adding:
```
std::optional<TraversalKind> getCheckTraversalKind() const override {
return TK_IgnoreUnlessSpelledInSource;
}
```
fixes it, but now templates seem to be skipped completely. and existing tests are not "passing" anymore:
```
template <typename T>
void testTemplate() {
T arr[] = {1, 2, 3, 4, 5};
std::span<T> s(arr, 5);
auto sub1 = s.subspan(0, 3);
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 'subspan()'
// CHECK-FIXES: auto sub1 = s.first(3);
auto sub2 = s.subspan(s.size() - 2);
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 'subspan()'
// CHECK-FIXES: auto sub2 = s.last(2);
__SIZE_TYPE__ n = 2;
auto sub3 = s.subspan(0, n);
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 'subspan()'
// CHECK-FIXES: auto sub3 = s.first(n);
auto sub4 = s.subspan(1, 2); // No warning
auto sub5 = s.subspan(2); // No warning
auto complex = s.subspan(0 + (s.size() - 2), 3); // No warning
auto complex2 = s.subspan(100 + (s.size() - 2)); // No warning
}
```
do you have any ideas?
https://github.com/llvm/llvm-project/pull/118074
More information about the cfe-commits
mailing list