[PATCH] D50883: [clang-tidy] Handle unique owning smart pointers in ExprMutationAnalyzer

Shuai Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 10 23:15:45 PDT 2018


shuaiwang added inline comments.


================
Comment at: unittests/clang-tidy/ExprMutationAnalyzerTest.cpp:658
+                     "void f() { UniquePtr<const S> x; x->mf(); }");
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
----------------
JonasToth wrote:
> Template testcases i miss:
> 
> ```
> // modifying
> template <typename T>
> void f() { UnqiuePtr<T> x; x->mf(); }
> 
> // constant
> template <typename T>
> void f2() { UnqiuePtr<T> x; x->cmf(); }
> 
> // indecidable for the template itself, but only the instantiations
> template <typename T>
> void f3() { T x; x->cmf(); }
> 
> struct const_class { void cmf() const; }
> struct modifying_class { void cmf(); };
> 
> void call_template() {
> // don't trigger
> f3<UniquePtr<const_class>>();
> // trigger modification
> f3<random_class*>();
> }
> 
> // again not decidable by the template itself
> template <typename T>
> void f4() { T t; *t; }
> 
> struct very_weird {
>     int& operator*() { return *new int(42); }
> };
> void call_template_deref() {
>   // no modification
>   f4<int*>();
>   // modification, because deref is not const
>   f4<UniquePtr<very_weird>>():
> }
> ```
Added a case with template. However I don't think we can do much whenever template appears: only the AST of **uninstantiated** template worth analyzing, because whatever analyze result (diag or fixit) would have to be applied to the template itself not the instantiations.
So the fact that the template argument of `f3` or `f4` could happen to be `UniquePtr` doesn't really matter when we analyze `f3` and `f4`, we have to analyze the way assuming the "worst" anyway.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50883





More information about the cfe-commits mailing list