[clang-tools-extra] [clang-tidy] Fix `readability-container-data-pointer` check (PR #165636)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 9 01:14:52 PST 2025
================
@@ -144,3 +150,9 @@ int *r() {
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
// CHECK-FIXES: return holder.v.data();
}
+
+void s(std::unique_ptr<std::vector<unsigned char>> p) {
+ f(&(*p)[0]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
+ // CHECK-FIXES: f((*p).data());
+}
----------------
vbvictor wrote:
```suggestion
}
void t(std::unique_ptr<container_without_data<unsigned char>> p) {
// p has no "data" member function, so no warning
f(&(*p)[0]);
}
template <typename T>
void u(std::unique_ptr<T> p) {
// we don't know if 'T' will always have "data" member function, so no warning
f(&(*p)[0]);
}
```
Lets add a couple of negative cases
https://github.com/llvm/llvm-project/pull/165636
More information about the cfe-commits
mailing list