[PATCH] D60507: [clang-tidy] new check: bugprone-unhandled-self-assignment
Tamás Zolnai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 23 10:40:10 PDT 2019
ztamas marked 5 inline comments as done.
ztamas added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp:34-36
+ const auto HasNoSelfCheck = cxxMethodDecl(unless(hasDescendant(
+ binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")),
+ has(ignoringParenCasts(cxxThisExpr()))))));
----------------
ztamas wrote:
> aaron.ballman wrote:
> > Will this also match code like:
> > ```
> > Frobble &Frobble::operator=(const Frobble &F) {
> > if (&F == this->whatever())
> > return *this;
> > }
> > ```
> > or, more insidiously:
> > ```
> > Frobble &Frobble::operator=(const Frobble &F) {
> > if (&F == whatever()) // whatever is a member function of Frobble
> > return *this;
> > }
> > ```
> >
> I'll check that case. The original hasLHS(...), hasRHS(...) might work with this use case too.
I added NotSelfCheck test case for this, which works correctly.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60507/new/
https://reviews.llvm.org/D60507
More information about the cfe-commits
mailing list