[PATCH] D41363: [clang-tidy] Adding Fuchsia checker for overloaded operators

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 20 10:37:18 PST 2017


aaron.ballman added inline comments.


================
Comment at: clang-tidy/fuchsia/OverloadedOperatorCheck.cpp:18
+
+AST_MATCHER(CXXMethodDecl, hasOverloadedOperator) {
+  if (Node.isCopyAssignmentOperator() || Node.isMoveAssignmentOperator())
----------------
JonasToth wrote:
> I think `isOverloadedOperator` is a better name.
I think `isFuchsiaOverloadedOperator()` is even better because of the extra work done by the checker (otherwise, it might be tempting to put this into ASTMatchers.h).


================
Comment at: clang-tidy/fuchsia/OverloadedOperatorCheck.cpp:30
+  if (const auto *D = Result.Nodes.getNodeAs<CXXMethodDecl>("decl"))
+    diag(D->getLocStart(), "operator overloading is disallowed");
+}
----------------
I think this could be better stated as "cannot overload %0" and pass in `D` (which should expand to something reasonable).


================
Comment at: test/clang-tidy/fuchsia-overloaded-operator.cpp:11
+public:
+  B &operator=(B other);
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:3: warning: operator overloading is disallowed [fuchsia-overloaded-operator]
----------------
While this is an overloaded assignment operator, it's grating for it not to accept a `const B&`.


https://reviews.llvm.org/D41363





More information about the cfe-commits mailing list