[PATCH] D18265: [clang-tidy] New: checker misc-assign-operator-return

Balogh, Ádám via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 5 06:29:29 PDT 2016


baloghadamsoftware added inline comments.

================
Comment at: clang-tidy/misc/AssignOperatorCheck.cpp:63
@@ +62,3 @@
+
+  Finder->addMatcher(returnStmt(IsBadReturnStatement, hasAncestor(IsGoodAssign))
+                         .bind("returnStmt"),
----------------
sbenza wrote:
> I dislike these uses of hasAnscestor. They are kind of slow.
> But more importantly, they break with nested functions/types.
> This particular example is not checking that the return statement is from the assignment operator, only that it is within it. For example, it would match a lambda.
> I think this would trip the check:
> 
>     F& operator=(const F& o) {
>       std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; });
>       return *this;
>     }
I can change it to hasDescendant if it is faster, but it does not solve the lambda problem. No solution for that comes to my mind with the existing matchers. Maybe a new matcher hasDescendantStatement could help which only traverses statements down the AST. Is this the right way to go?


http://reviews.llvm.org/D18265





More information about the cfe-commits mailing list