[PATCH] D80490: Check for rule of five and zero.

Nithin VR via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 24 04:16:45 PDT 2020


vrnithinkumar created this revision.
vrnithinkumar added reviewers: aaron.ballman, alexfh, jbcoe, dblaikie, rsmith.
Herald added subscribers: cfe-commits, kbarton, mgorny, nemanjai.
Herald added a project: clang.

New check to check if a class defines all special members of none of them. This also known as rule of five and zero.
Specified in CppCoreGuidelines: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-default-operation-define-or-delete-them-all.
In summary the check will

- Checks class defines all special members of none of them.
- It also see if the base class deletes the special members or not.
- Has two modes with the flag strict-check.
- Strict mode will check all or nothing strictly.

For some combination, compiler explicitly delete the special members or  does not declare implicitly. In that case don'nt have to define all the special members. 
For example, in case of defining all members except move constructor and move assignment compiler will not implicitly declare the move constructor and move assignment.
For non strict mode we will consider these combinations as safe.

I found one review https://reviews.llvm.org/D16376 already related to this. 
I modified my changes based on this. But I could not find out why this got abandoned.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80490

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/RuleOfFiveAndZeroCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/RuleOfFiveAndZeroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-rule-of-five-and-zero.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-rule-of-five-and-zero-strict.cpp
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-rule-of-five-and-zero.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80490.265920.patch
Type: text/x-patch
Size: 28977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200524/6a3e1a1a/attachment-0001.bin>


More information about the cfe-commits mailing list