[PATCH] D52771: [private][clang-tidy] Non-private member variables in classes (MISRA, CppCoreGuidelines, HICPP)

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 3 02:55:05 PDT 2018


lebedev.ri updated this revision to Diff 168088.
lebedev.ri added a subscriber: cfe-commits.
lebedev.ri added a comment.

Finds classes that not only contain the data (non-static member variables),
but also have logic (non-static member functions), and diagnoses all member
variables that have any other scope other than `private`. They should be
made `private`, and manipulated exclusively via the member functions.

Optionally, classes with all member variables being `public` could be
ignored, and optionally all `public` member variables could be ignored.

Options
-------

- IgnoreClassesWithAllMemberVariablesBeingPublic

  Allows to completely ignore classes if **all** the member variables in that class have `public` visibility.

- IgnorePublicMemberVariables

  Allows to ignore (not diagnose) **all** the member variables with `public` visibility scope.

References:

- MISRA 11-0-1 Member data in non-POD class types shall be private.
- http://www.codingstandard.com/rule/11-1-1-declare-all-data-members-private/
- https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c2-use-class-if-the-class-has-an-invariant-use-struct-if-the-data-members-can-vary-independently
- https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-private
- https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-protected


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52771

Files:
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
  clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-non-private-member-variables-in-classes.rst
  docs/clang-tidy/checks/hicpp-non-private-member-variables-in-classes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst
  test/clang-tidy/misc-non-private-member-variables-in-classes.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52771.168088.patch
Type: text/x-patch
Size: 28262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181003/a4a9239e/attachment-0001.bin>


More information about the cfe-commits mailing list