[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 26 16:18:14 PDT 2023


https://github.com/5chmidti commented:

I noticed a problem with your matcher, so I reviewed the rest of it while I was at it.

The problem is that you do not consider a type-dependent `std::shared_ptr<T>` and the following test case fails:

```c++
template <typename T>
void dependentType() {
  std::shared_ptr<T> p;
  T y = std::move(*p);
  // CHECK-FIXES: *std::move(p)
}
// CHECK-MESSAGES: :[[@LINE-3]]:11: warning: don't move the contents out of a shared pointer, as other accessors expect them to remain in a determinate state [bugprone-move-shared-pointer-contents]
```

In this case, your `callee` is no longer a `functionDecl` but an `unresolvedLookupExpr` and the `*` operator is a `UnaryOperator` instead of a `cxxOperatorCallExpr`.

Otherwise, looks like a good check to have.

https://github.com/llvm/llvm-project/pull/67467


More information about the cfe-commits mailing list