This is an archive of the discontinued LLVM Phabricator instance.

[PATCH] Support C++ Core Guidelines copy assignment restrictions
ClosedPublic

Authored by aaron.ballman on Oct 7 2015, 7:00 AM.

Details

Summary

Eugene pointed out to me that our existing misc-assign-operator-signature check was almost perfectly implementing the C++ Core Guideline guidance for Copy and move, found here: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-ccopy-copy-and-move. The only part that was missing was ensuring that the operator wasn't marked as virtual.

In this patch, I've implemented the check for the virtual qualifier, and registered the checker as a cppcoreguideline checker in addition to its usual place in misc.

~Aaron

Diff Detail

Event Timeline

aaron.ballman retitled this revision from to [PATCH] Support C++ Core Guidelines copy assignment restrictions.
aaron.ballman updated this object.
aaron.ballman added a subscriber: cfe-commits.
Eugene.Zelenko edited edge metadata.Oct 7 2015, 9:50 AM

I think it'll be fine to rename check without leaving traces of misc. Same thing happened with modernize-shrink-to-fit.

I think it'll be fine to rename check without leaving traces of misc. Same thing happened with modernize-shrink-to-fit.

I think the difference here is that many C++ Core Guideline checks are... chatty, and so these checks are likely to not be enabled (especially on existing code bases). By leaving the check in misc-*, it is more likely to provide value to users that aren't able to use the cppcoreguidelines-* checks yet.

mgehre edited edge metadata.Oct 7 2015, 1:16 PM

The user will see [cppcoreguidelines-c-copy-assignment-signature] in warnings, but there is no
docs/clang-tidy/checks/cppcoreguidelines-c-copy-assignment-signature.rst.

The user won't know that he needs to look for misc-assign-operator-signature.

Maybe create a link to docs/clang-tidy/checks/misc-assign-operator-signature.rst?
(and also add it to docs/clang-tidy/checks/list.rst)

Also, users reading the documentation will not see that cppcoreguidelines-c-copy-assignment-signature is available.

sbenza edited edge metadata.Oct 7 2015, 1:18 PM

I think it'll be fine to rename check without leaving traces of misc. Same thing happened with modernize-shrink-to-fit.

I think the difference here is that many C++ Core Guideline checks are... chatty, and so these checks are likely to not be enabled (especially on existing code bases). By leaving the check in misc-*, it is more likely to provide value to users that aren't able to use the cppcoreguidelines-* checks yet.

Now that we are registering checks with more than one name, it might be a good idea to add a dedup step to avoid redundant warnings and/or wasted resources.
Not on this change but something to consider.

sbenza accepted this revision.Oct 7 2015, 1:18 PM
sbenza edited edge metadata.
This revision is now accepted and ready to land.Oct 7 2015, 1:18 PM
aaron.ballman closed this revision.Oct 13 2015, 8:27 AM

The user will see [cppcoreguidelines-c-copy-assignment-signature] in warnings, but there is no
docs/clang-tidy/checks/cppcoreguidelines-c-copy-assignment-signature.rst.

The user won't know that he needs to look for misc-assign-operator-signature.

I think this is a good point, but requires more engineering and discussion than this single patch should handle. Checkers registered under multiple names will have to figure something out for documentation.

Maybe create a link to docs/clang-tidy/checks/misc-assign-operator-signature.rst?
(and also add it to docs/clang-tidy/checks/list.rst)

That's not a bad fallback solution if we don't come up with something better as part of the larger documentation discussion.

Also, users reading the documentation will not see that cppcoreguidelines-c-copy-assignment-signature is available.

-checks=* -list-checks does show it as being available.

I have commit in r250165. As for the documentation discussion, I would like to have one, but not when I'm about to embark on a two-week vacation. If the discussion doesn't start by early Nov, I hope to circle back around to it then.

Thanks!

~Aaron