2014-03-05 21:14:32 +08:00
|
|
|
//===--- MiscTidyModule.cpp - clang-tidy ----------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
|
|
|
#include "../ClangTidyModule.h"
|
|
|
|
#include "../ClangTidyModuleRegistry.h"
|
2016-01-09 00:37:11 +08:00
|
|
|
#include "DefinitionsInHeadersCheck.h"
|
2016-11-08 15:50:19 +08:00
|
|
|
#include "MisplacedConstCheck.h"
|
2015-09-29 21:12:21 +08:00
|
|
|
#include "NewDeleteOverloadsCheck.h"
|
2015-09-30 22:09:38 +08:00
|
|
|
#include "NonCopyableObjects.h"
|
[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
llvm-svn: 344757
2018-10-19 04:16:44 +08:00
|
|
|
#include "NonPrivateMemberVariablesInClassesCheck.h"
|
2016-04-27 01:30:30 +08:00
|
|
|
#include "RedundantExpressionCheck.h"
|
2015-03-02 18:46:43 +08:00
|
|
|
#include "StaticAssertCheck.h"
|
2015-10-10 04:42:44 +08:00
|
|
|
#include "ThrowByValueCatchByReferenceCheck.h"
|
2016-11-08 15:50:19 +08:00
|
|
|
#include "UnconventionalAssignOperatorCheck.h"
|
2015-03-09 19:48:54 +08:00
|
|
|
#include "UniqueptrResetReleaseCheck.h"
|
2015-08-01 00:08:10 +08:00
|
|
|
#include "UnusedAliasDeclsCheck.h"
|
2015-07-20 09:06:44 +08:00
|
|
|
#include "UnusedParametersCheck.h"
|
2016-04-19 21:48:39 +08:00
|
|
|
#include "UnusedUsingDeclsCheck.h"
|
2014-03-05 21:14:32 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
2015-03-02 20:25:03 +08:00
|
|
|
namespace misc {
|
2014-03-05 21:14:32 +08:00
|
|
|
|
|
|
|
class MiscModule : public ClangTidyModule {
|
|
|
|
public:
|
|
|
|
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
2016-01-09 00:37:11 +08:00
|
|
|
CheckFactories.registerCheck<DefinitionsInHeadersCheck>(
|
|
|
|
"misc-definitions-in-headers");
|
2018-09-20 08:02:55 +08:00
|
|
|
CheckFactories.registerCheck<MisplacedConstCheck>("misc-misplaced-const");
|
2015-09-29 21:12:21 +08:00
|
|
|
CheckFactories.registerCheck<NewDeleteOverloadsCheck>(
|
|
|
|
"misc-new-delete-overloads");
|
2015-09-30 22:09:38 +08:00
|
|
|
CheckFactories.registerCheck<NonCopyableObjectsCheck>(
|
|
|
|
"misc-non-copyable-objects");
|
[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
llvm-svn: 344757
2018-10-19 04:16:44 +08:00
|
|
|
CheckFactories.registerCheck<NonPrivateMemberVariablesInClassesCheck>(
|
|
|
|
"misc-non-private-member-variables-in-classes");
|
2016-04-27 01:30:30 +08:00
|
|
|
CheckFactories.registerCheck<RedundantExpressionCheck>(
|
|
|
|
"misc-redundant-expression");
|
2016-11-08 15:50:19 +08:00
|
|
|
CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert");
|
2015-10-10 04:42:44 +08:00
|
|
|
CheckFactories.registerCheck<ThrowByValueCatchByReferenceCheck>(
|
|
|
|
"misc-throw-by-value-catch-by-reference");
|
2018-09-20 08:02:55 +08:00
|
|
|
CheckFactories.registerCheck<UnconventionalAssignOperatorCheck>(
|
|
|
|
"misc-unconventional-assign-operator");
|
2015-03-09 19:48:54 +08:00
|
|
|
CheckFactories.registerCheck<UniqueptrResetReleaseCheck>(
|
2014-12-05 19:59:05 +08:00
|
|
|
"misc-uniqueptr-reset-release");
|
2015-08-01 00:08:10 +08:00
|
|
|
CheckFactories.registerCheck<UnusedAliasDeclsCheck>(
|
|
|
|
"misc-unused-alias-decls");
|
2015-07-20 09:06:44 +08:00
|
|
|
CheckFactories.registerCheck<UnusedParametersCheck>(
|
|
|
|
"misc-unused-parameters");
|
2016-04-19 21:48:39 +08:00
|
|
|
CheckFactories.registerCheck<UnusedUsingDeclsCheck>(
|
|
|
|
"misc-unused-using-decls");
|
2014-03-05 21:14:32 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-02 20:25:03 +08:00
|
|
|
} // namespace misc
|
|
|
|
|
2014-03-05 21:14:32 +08:00
|
|
|
// Register the MiscTidyModule using this statically initialized variable.
|
2015-03-02 20:25:03 +08:00
|
|
|
static ClangTidyModuleRegistry::Add<misc::MiscModule>
|
2016-11-08 15:50:19 +08:00
|
|
|
X("misc-module", "Adds miscellaneous lint checks.");
|
2014-03-05 21:14:32 +08:00
|
|
|
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the MiscModule.
|
|
|
|
volatile int MiscModuleAnchorSource = 0;
|
|
|
|
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|