[PATCH] D117306: [clang-tidy] Add new check 'shared-ptr-array-mismatch'.

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 3 05:05:52 PST 2022


njames93 added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp:41-47
+  const Decl *ParentDecl = ConstructParents.begin()->get<Decl>();
+  if (!ParentDecl)
+    return nullptr;
+  if (const auto *ParentVar = dyn_cast<VarDecl>(ParentDecl))
+    return ParentVar;
+  if (const auto *ParentField = dyn_cast<FieldDecl>(ParentDecl))
+    return ParentField;
----------------



================
Comment at: clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.h:40
+  /// in this class.
+  virtual SmartPtrClassMatcher getSmartPointerClassMatcher() const = 0;
+
----------------
LegalizeAdulthood wrote:
> There's only one implementation of this abstract method declared here.
> 
> Why the extra level in the class hierarchy if there's only one implementation?
The idea I think is so that this can be used to make a similar check for `unique_ptr`. However I almost don't see the need for this, and I'd argue that they should both be implemented in one check. So this will detect 
```lang=c++
std::shared_ptr<int> X = new int[5];
std::unique_ptr<int> Y = new int[5];
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117306



More information about the cfe-commits mailing list