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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 18 14:01:56 PST 2019


aaron.ballman added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp:73-79
+  if (const auto *MemberCall =
+          Result.Nodes.getNodeAs<CXXMemberCallExpr>(MutatingCallName)) {
+    diag(MemberCall->getBeginLoc(), "call mutates copied object");
+  } else if (const auto *Assignment =
+                 Result.Nodes.getNodeAs<Expr>(MutatingOperatorName)) {
+    diag(Assignment->getBeginLoc(), "mutating copied object");
+  }
----------------
You can elide the curly braces here per our usual coding conventions.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-oop58-cpp.rst:12
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP58-CPP.+Copy+operations+must+not+mutate+the+source+object>`_.
\ No newline at end of file

----------------
Please add the newline to the end of the file.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cert-oop58-cpp.cpp:1
+// RUN: %check_clang_tidy %s cert-oop58-cpp %t -std=c++11-or-later
+
----------------
This `-std` looks incorrect to me -- you can remove it entirely (we already default to later than C++11 anyway).


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cert-oop58-cpp.cpp:150
+} // namespace test_mutating_function_on_nested_object
\ No newline at end of file

----------------
Please add the newline to the end of the file.


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

https://reviews.llvm.org/D70052





More information about the cfe-commits mailing list