Check for classes that violate the rule of five and zero as specified in CppCoreGuidelines:
"If a class defines or deletes a default operation then it should define or delete them all."
Differential D22513
[clang-tidy] add check cppcoreguidelines-special-member-functions jbcoe on Jul 19 2016, 7:23 AM. Authored by
Details Check for classes that violate the rule of five and zero as specified in CppCoreGuidelines: "If a class defines or deletes a default operation then it should define or delete them all."
Diff Detail Event TimelineComment Actions Please mention this check in docs/ReleaseNotes.rst. See pre-4.0 branch versions as example.
Comment Actions Since rule name is different in C++98/03 and C++11 or newer it will make sense to create two checks which will work only for their respective versions (of course, implementation should be shared). Or create alias name. Check is still not mentioned in docs/ReleaseNotes.rst. Comment Actions I will look again soon, but it looks much better right now!
Comment Actions Rename to cppcoreguidelines-special-member-functions to avoid the duplication required with naming it rule-of-3 and rule-of-5. Reduce code duplication by iterating over a list of matchers. Use dense map. [FIXME: I can't get DenseMap to work with the DenseMapInfo defined in the header. IdentifierNamingCheck.cpp does this without any issues but I hit compiler errors around DenseMap and SourceLocation. Moving the specialisation from the header to the source of SpecialMemberFunctionsCheck suffices to repeat the problem. Any input here would be appreciated.]
Comment Actions Minor changes from review.
Comment Actions LGTM, thank you for the check! The oddness with the DenseMap can wait until a follow-up patch, btw. Comment Actions Thanks for the new check! Looks awesome! A couple of late comments inline.
Comment Actions I have an segfault on all the source files of my project when I enable this check (it works ok when I disable this check). Sorry I don't have time to post a minimal source file producing the segfault. I will maybe tomorrow, or in two weeks. |
no comma after all. But I might be wrong because I am not certified grammar nazi