diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2018-10-18 20:16:44 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2018-10-18 20:16:44 +0000 |
commit | 6d97c0a4967f92e6c83afe2c1986cfdd5e848e0a (patch) | |
tree | a9dc0ff45e11ea057bc5d3b366e8f5da3f17a0ca /clang-tools-extra/docs | |
parent | 65731b8b2cc88d80d341ad262f063e02b7a338c8 (diff) |
[clang-tidy] Non-private member variables in classes (MISRA, CppCoreGuidelines, HICPP)
Summary:
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.
* 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
Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun
Reviewed By: aaron.ballman
Subscribers: Eugene.Zelenko, zinovy.nis, cfe-commits, rnkovacs, nemanjai, mgorny, xazax.hun, kbarton
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D52771
Diffstat (limited to 'clang-tools-extra/docs')
4 files changed, 52 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 17be5cea258..1af6d050206 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -103,6 +103,13 @@ Improvements to clang-tidy Flags uses of ``absl::StrCat()`` to append to a ``std::string``. Suggests ``absl::StrAppend()`` should be used instead. +- New :doc:`misc-non-private-member-variables-in-classes + <clang-tidy/checks/misc-non-private-member-variables-in-classes>` check. + + 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``. + - New :doc:`modernize-concat-nested-namespaces <clang-tidy/checks/modernize-concat-nested-namespaces>` check. @@ -134,6 +141,12 @@ Improvements to clang-tidy <clang-tidy/checks/readability-uppercase-literal-suffix>` added. +- New alias :doc:`cppcoreguidelines-non-private-member-variables-in-classes + <clang-tidy/checks/cppcoreguidelines-non-private-member-variables-in-classes>` + to :doc:`misc-non-private-member-variables-in-classes + <clang-tidy/checks/misc-non-private-member-variables-in-classes>` + added. + - New alias :doc:`hicpp-uppercase-literal-suffix <clang-tidy/checks/hicpp-uppercase-literal-suffix>` to :doc:`readability-uppercase-literal-suffix diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-non-private-member-variables-in-classes.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-non-private-member-variables-in-classes.rst new file mode 100644 index 00000000000..293e1bbe094 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-non-private-member-variables-in-classes.rst @@ -0,0 +1,11 @@ +.. title:: clang-tidy - cppcoreguidelines-non-private-member-variables-in-classes +.. meta:: + :http-equiv=refresh: 5;URL=misc-non-private-member-variables-in-classes.html + +cppcoreguidelines-non-private-member-variables-in-classes +========================================================= + +The cppcoreguidelines-non-private-member-variables-in-classes check is an alias, +please see +`misc-non-private-member-variables-in-classes <misc-non-private-member-variables-in-classes.html>`_ +for more information. diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index f5d4ac898ce..fc915d75b76 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -91,6 +91,7 @@ Clang-Tidy Checks cppcoreguidelines-interfaces-global-init cppcoreguidelines-narrowing-conversions cppcoreguidelines-no-malloc + cppcoreguidelines-non-private-member-variables-in-classes (redirects to misc-non-private-member-variables-in-classes) <cppcoreguidelines-non-private-member-variables-in-classes> cppcoreguidelines-owning-memory cppcoreguidelines-pro-bounds-array-to-pointer-decay cppcoreguidelines-pro-bounds-constant-array-index @@ -165,6 +166,7 @@ Clang-Tidy Checks misc-misplaced-const misc-new-delete-overloads misc-non-copyable-objects + misc-non-private-member-variables-in-classes misc-redundant-expression misc-static-assert misc-throw-by-value-catch-by-reference diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst new file mode 100644 index 00000000000..db88c9b1cff --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst @@ -0,0 +1,26 @@ +.. title:: clang-tidy - misc-non-private-member-variables-in-classes + +misc-non-private-member-variables-in-classes +============================================ + +`cppcoreguidelines-non-private-member-variables-in-classes` redirects here +as an alias for this check. + +Finds classes that contain non-static data members in addition to non-static +member functions and diagnose all data members declared with a non-``public`` +access specifier. The data members should be declared as ``private`` and +accessed through member functions instead of exposed to derived classes or +class consumers. + +Options +------- + +.. option:: IgnoreClassesWithAllMemberVariablesBeingPublic + + Allows to completely ignore classes if **all** the member variables in that + class a declared with a ``public`` access specifier. + +.. option:: IgnorePublicMemberVariables + + Allows to ignore (not diagnose) **all** the member variables declared with + a ``public`` access specifier. |