[PATCH] D70052: [clang-tidy] Add misc-mutating-copy check

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 9 10:25:23 PST 2019


aaron.ballman accepted this revision.
aaron.ballman added a comment.

In D70052#1750664 <https://reviews.llvm.org/D70052#1750664>, @gbencze wrote:

> In D70052#1749730 <https://reviews.llvm.org/D70052#1749730>, @JonasToth wrote:
>
> > There is a `ExprMutAnalyzer` that is able to find mutation of expressions in general (even though it is kinda experimental still). Maybe that should be utilized somehow? I think the current implementation does not cover when the address is taken and mutation happens through pointers/references in free standing functions, does it?
> >
> > On the other hand it makes the check more complicated, slower. Additionally the most cases are catched with this version, i guess.
>
>
> You're right, the current version does not cover mutations through pointers and references. I'm not sure how common these would be, but `ExprMutAnalyzer` seems like a great option if we wanted to add support for those cases as well.


It also doesn't cover mutations through function calls. e.g.,

  void some_func(S &); // Could mutate the passed object
  
  struct S {
    int i, j;
    S(S &s) : i(s.i), j(s.j) { some_func(s); }
  };

However, I think the clang-tidy check will suffice for catching a significant percentage of mutating copy bugs so it seems reasonable to keep this rather than insist on a static analyzer check.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70052/new/

https://reviews.llvm.org/D70052





More information about the cfe-commits mailing list