Warn when the return type of assign operators is not Class&.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Sorry for the long delay.
This looks mostly fine, but I wonder if it makes sense to check for other possible mistakes, e.g.:
T& operator=(T&); const T& operator=(const T&) const; virtual T& operator=(const T&);
Also, it seems like this issue is not specific to the Google C++ Style, so it could be put into misc/ or it may even be reasonable to have a compiler warning for this.
clang-tidy/google/AssignOperatorSignatureCheck.cpp | ||
---|---|---|
23 ↗ | (On Diff #17301) | I guess you missed "unless(isImplicit())" (and a test for it). And maybe also unless(isInTemplateInstantiation()) (especially, if you would want to provide a fixit for the "const T& operator=(const T&)" case). |
clang-tidy/google/AssignOperatorSignatureCheck.h | ||
25 ↗ | (On Diff #17301) | Unfortunately, this needs to be done the old way. LLVM supports MSVS 2013 which doesn't support this form of constructor delegation. |
Added more checks.
Also fixed assigning by-value and assigning from a different type. Those are ok.
clang-tidy/google/AssignOperatorSignatureCheck.cpp | ||
---|---|---|
23 ↗ | (On Diff #17301) | I could add unless(isImplicit()), but the implicit one will have the right signature, so it shouldn't match anyway. |
clang-tidy/google/AssignOperatorSignatureCheck.h | ||
25 ↗ | (On Diff #17301) | Done. |
What about virtual T& operator=(const T&);? It looks like a bad pattern, IMHO.
Also, it looks like the check is not specific to Google and it's not exactly about readability. Maybe move it to misc/?
clang-tidy/google/AssignOperatorSignatureCheck.cpp | ||
---|---|---|
23 ↗ | (On Diff #17301) | Reasonable. Maybe a comment would not be useless. |
wrt virtual, I don't know. Maybe there is a good reason to make it virtual? Doesn't seem like a common mistake anyway.
wrt category for the check, I agree. I'll move it once we have no more comments on the code.
clang-tidy/google/AssignOperatorSignatureCheck.cpp | ||
---|---|---|
23 ↗ | (On Diff #17301) | I just added the call. It is correct and self documenting. |
test/clang-tidy/misc-assign-operator.cpp | ||
---|---|---|
1 ↗ | (On Diff #19583) | Please name the file "misc-assign-operator-signature.cpp". |