summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-self-assign.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded ↵Roman Lebedev2018-04-071-50/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | self-assignment (classes) Summary: This has just bit me, so i though it would be nice to avoid that next time :) Motivational case: https://godbolt.org/g/cq9UNk Basically, it's likely to happen if you don't like shadowing issues, and use `-Wshadow` and friends. And it won't be diagnosed by clang. The reason is, these self-assign diagnostics only work for builtin assignment operators. Which makes sense, one could have a very special operator=, that does something unusual in case of self-assignment, so it may make sense to not warn on that. But while it may be intentional in some cases, it may be a bug in other cases, so it would be really great to have some diagnostic about it... Reviewers: aaron.ballman, rsmith, rtrieu, nikola, rjmccall, dblaikie Reviewed By: rjmccall Subscribers: EricWF, lebedev.ri, thakis, Quuxplusone, cfe-commits Differential Revision: https://reviews.llvm.org/D44883 llvm-svn: 329493
* PR12214 - Warn on suspicious self-compound-assignments.Nikola Smiljanic2014-05-301-0/+3
| | | | llvm-svn: 209867
* Implement -Wself-assign, which warns on code such as:Chandler Carruth2011-01-041-0/+47
int x = 42; x = x; // Warns here. The warning avoids macro expansions, templates, user-defined assignment operators, and volatile types, so false positives are expected to be low. The common (mis-)use of this code pattern is to silence unused variable warnings, but a more idiomatic way of doing that is '(void)x;'. A follow-up to this will add a note and fix-it hint suggesting this replacement in cases where the StmtExpr consists precisely of the self assignment. llvm-svn: 122804
OpenPOWER on IntegriCloud