[PATCH] D25898: [clang-tidy] Enhance modernize-make-unique to handle unique_ptr.reset()

Piotr Padlewski via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 23 07:08:13 PDT 2016


Prazek added inline comments.


================
Comment at: test/clang-tidy/modernize-make-shared.cpp:122
+  Pderived = std::shared_ptr<Derived>(new Derived());
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use std::make_shared instead
+  // CHECK-FIXES: Pderived = std::make_shared<Derived>();
----------------
malcolm.parsons wrote:
> Prazek wrote:
> > I think the warning here could be better. The user is using make_shared here.
> > Maybe ' warning: use std::make_shared with zero arguments ...', but only in this case
> The user isn't using make_shared.
true, I've read that incorectly


================
Comment at: test/clang-tidy/modernize-make-shared.cpp:129
+  // FIXME: OK to replace when auto is not used
+  std::shared_ptr<Base> PBase = std::shared_ptr<Base>(new Derived());
+
----------------
malcolm.parsons wrote:
> Prazek wrote:
> > I think it is good to replace it even with auto, like
> > auto PBase = std::make_shared<Base>(new Derived());
> > 
> > For shared_ptr we can even do better, that we can't do for unique_ptr - we
> > coud change it to
> > auto PBase = std::make_shared<Derived>();
> > because all conversions works.
> > Of course not in this patch, but it would be good to leave a comment about this here.
> A smart pointer to Derived cannot be reset with a pointer to Base.
oh yea, I was only thinking about downcasting smart pointer


https://reviews.llvm.org/D25898





More information about the cfe-commits mailing list