This is an archive of the discontinued LLVM Phabricator instance.

Verify assign operator signatures.
ClosedPublic

Authored by sbenza on Dec 15 2014, 12:22 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

sbenza updated this revision to Diff 17300.Dec 15 2014, 12:22 PM
sbenza retitled this revision from to Verify assign operator signatures..
sbenza updated this object.
sbenza edited the test plan for this revision. (Show Details)
sbenza added a reviewer: alexfh.
sbenza added a subscriber: Unknown Object (MLST).
sbenza updated this revision to Diff 17301.Dec 15 2014, 1:03 PM

Ignore private operators too.

alexfh edited edge metadata.Jan 9 2015, 5:45 AM

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.

sbenza added a comment.Feb 5 2015, 2:44 PM

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.

sbenza updated this revision to Diff 19434.Feb 5 2015, 2:44 PM
sbenza edited edge metadata.

Add more checks.

alexfh added a comment.Feb 6 2015, 5:32 AM

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.

sbenza updated this revision to Diff 19489.Feb 6 2015, 9:16 AM

Add isImplicit()

sbenza added a comment.Feb 6 2015, 9:16 AM

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.

alexfh accepted this revision.Feb 9 2015, 8:02 AM
alexfh edited edge metadata.

Looks good! (After moving to misc/.)

This revision is now accepted and ready to land.Feb 9 2015, 8:02 AM
sbenza updated this revision to Diff 19583.Feb 9 2015, 8:14 AM
sbenza edited edge metadata.

Move to misc-

alexfh added inline comments.Feb 9 2015, 8:45 AM
test/clang-tidy/misc-assign-operator.cpp
1 ↗(On Diff #19583)

Please name the file "misc-assign-operator-signature.cpp".

sbenza updated this revision to Diff 19585.Feb 9 2015, 8:47 AM

Rename test file

alexfh added a comment.Feb 9 2015, 9:51 AM

Looks good!

This revision was automatically updated to reflect the committed changes.