[PATCH] D108893: clang-tidy: introduce readability-containter-data-pointer check

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 13 10:41:04 PDT 2021


aaron.ballman accepted this revision.
aaron.ballman added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp:63
+                                            hasType(Container),
+                                            hasType(pointsTo(Container)),
+                                            hasType(references(Container))))))
----------------
compnerd wrote:
> aaron.ballman wrote:
> > Same question here about `pointsTo()`.
> This is actually meant to catch cases such as references to UnOp(DRE).
Good catch and thank you for all the off-list discussion on this point!


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability-container-data-pointer.cpp:104
+  // CHECK-MESSAGES-NOT: :[[@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]
+}
----------------
Can you add one more test for how this behaves on uninstantiated templates?
```
template <typename Ty>
void func(const std::vector<Ty> &Vec) {
  const Ty *Ptr = &Vec[0]; // Should diagnose and provide a fix-it despite not instantiating func()
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108893/new/

https://reviews.llvm.org/D108893



More information about the cfe-commits mailing list