[clang-tools-extra] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 12 14:04:17 PDT 2023
================
@@ -0,0 +1,23 @@
+.. title:: clang-tidy - performance-move-smart-pointer-contents
+
+performance-move-smart-pointer-contents
+=======================================
+
+Given a smart pointer containing a movable type, such as a
+`std::unique_ptr<SomeProtocolBuffer>`, it's possible to move the contents of the
+pointer rather than the pointer itself (ie `std::move(*p)` rather than
+`*std::move(p)`). Doing so is a pessimization, as if the type could be efficiently
+moved we wouldn't need to put it in a `unique_ptr` to begin with.
----------------
PiotrZSL wrote:
"Doing so is a pessimization, as if the type could be efficiently
moved we wouldn't need to put it in a `unique_ptr` to begin with."
You do not know a reasons why someone used unique_ptr, maybe they use custom deleter, maybe they follow some guidelines, maybe they want object to be on heap, not on stack.
https://github.com/llvm/llvm-project/pull/66139
More information about the cfe-commits
mailing list