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

via Openmp-commits openmp-commits at lists.llvm.org
Fri Dec 1 15:58:59 PST 2023

pizzud wrote:

> 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.

I'm really struggling with this, and also with getting the git history right after three months oops. The UnaryOperator is matchable without much difficulty, but there appears to be no way to introspect the UnresolvedLookupExpr to ensure I'm matching calls to `std::move`.


More information about the Openmp-commits mailing list