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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 15 10:06:03 PST 2019


aaron.ballman added a comment.

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

> In D70052#1740235 <https://reviews.llvm.org/D70052#1740235>, @Eugene.Zelenko wrote:
>
> > If this is CERT rule, why check is not placed in relevant module?
>
>
> To be honest I was hoping for some feedback on this as I wasn't sure what the best place for this check would be. Quite a few CERT rules seem to be implemented in other modules and have cert aliases. 
>  Do you think this check should be moved there or should I just add an alias?


I'd probably implement this only in the `cert` module, but if we wanted to expose it outside of there as well, I'd suggest `bugprone`.



================
Comment at: clang-tools-extra/test/clang-tidy/misc-mutating-copy.cpp:107
+};
+} // namespace test_mutating_other_object
----------------
I think a case like this should also diagnose:
```
class S {
  int a;
public:
  void fine_func() const;
  void questionable_func();
  void bad_func() { a = 12; }

  S(S& other) : a(other.a) {
    other.fine_func(); // This is fine
    other.bad_func(); // This is a problem
    other.questionable_func(); // Not certain what to do here.
  }

  bool operator==(const S& other) { return a == other.a; }
};
```


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

https://reviews.llvm.org/D70052





More information about the cfe-commits mailing list