[PATCH] D151431: [clang-tidy] Add check bugprone-unique-ptr-array-mismatch.

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 25 09:43:10 PDT 2023


PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

LGTM, But:

- Align check description before committing.
- Consider adding some test with std::unique_ptr behind typedef.
- Consider adding test with unique_ptr depend on template argument but without specializations (like f_tmpl but without f5 function).

General issue that I got with this test (and test for shared_ptr) is that actually there is no issue here.
For POD types it actually doesn't mater if you use `delete` or `delete[]`. This of course isn't portable and fall into implementation specific.
But can read about this in https://itanium-cxx-abi.github.io/cxx-abi/abi.html#array-cookies
This is why I would like to see NonPOD types instead of POD ones to be used with unique_ptr.
On GCC/Clang memory will be fully released (POD) types or corrupted (non POD types).



================
Comment at: clang-tools-extra/clang-tidy/bugprone/UniquePtrArrayMismatchCheck.h:16-23
+/// Find `std::unique_ptr<T>(new T[...])`, replace it (if applicable) with
+/// `std::unique_ptr<T[]>(new T[...])`.
+///
+/// Example:
+///
+/// \code
+///   std::unique_ptr<int> PtrArr{new int[10]};
----------------
this should be same as in release notes ("Finds initializations of C++ unique pointers to non-array type that are initialized with an array.")


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151431



More information about the cfe-commits mailing list