[clang-tidy] Handle unique owning smart pointers in ExprMutationAnalyzer
authorShuai Wang <shuaiwang@google.com>
Tue, 11 Sep 2018 17:33:12 +0000 (17:33 +0000)
committerShuai Wang <shuaiwang@google.com>
Tue, 11 Sep 2018 17:33:12 +0000 (17:33 +0000)
commitea85b52732827eb41913a1cd60ae66b56e99de82
treee8194ea63bd5467b25dab569aca01a721bdc9a9c
parentaca532f14dd3360d0025e0b9d5ae606be046cf79
[clang-tidy] Handle unique owning smart pointers in ExprMutationAnalyzer

Summary:
For smart pointers like std::unique_ptr which uniquely owns the
underlying object, treat the mutation of the pointee as mutation of the
smart pointer itself.

This gives better behavior for cases like this:
```
void f(std::vector<std::unique_ptr<Foo>> v) { // undesirable analyze result of `v` as not mutated.
  for (auto& p : v) {
      p->mutate(); // only const member function `operator->` is invoked on `p`
  }
}
```

Reviewers: hokein, george.karpenkov

Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits

Differential Revision: https://reviews.llvm.org/D50883

llvm-svn: 341967
clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp
clang-tools-extra/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp