1//===-- CppCoreGuidelinesTidyModule.cpp - clang-tidy ----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "../ClangTidy.h"
10#include "../ClangTidyModule.h"
11#include "../ClangTidyModuleRegistry.h"
12#include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
13#include "../misc/UnconventionalAssignOperatorCheck.h"
14#include "../modernize/AvoidCArraysCheck.h"
15#include "../modernize/MacroToEnumCheck.h"
16#include "../modernize/UseDefaultMemberInitCheck.h"
17#include "../modernize/UseOverrideCheck.h"
18#include "../performance/NoexceptDestructorCheck.h"
19#include "../performance/NoexceptMoveConstructorCheck.h"
20#include "../performance/NoexceptSwapCheck.h"
21#include "../readability/MagicNumbersCheck.h"
22#include "AvoidCapturingLambdaCoroutinesCheck.h"
23#include "AvoidConstOrRefDataMembersCheck.h"
24#include "AvoidDoWhileCheck.h"
25#include "AvoidGotoCheck.h"
26#include "AvoidNonConstGlobalVariablesCheck.h"
27#include "AvoidReferenceCoroutineParametersCheck.h"
28#include "InitVariablesCheck.h"
29#include "InterfacesGlobalInitCheck.h"
30#include "MacroUsageCheck.h"
31#include "MisleadingCaptureDefaultByValueCheck.h"
32#include "MissingStdForwardCheck.h"
33#include "NarrowingConversionsCheck.h"
34#include "NoMallocCheck.h"
35#include "NoSuspendWithLockCheck.h"
36#include "OwningMemoryCheck.h"
37#include "PreferMemberInitializerCheck.h"
38#include "ProBoundsArrayToPointerDecayCheck.h"
39#include "ProBoundsConstantArrayIndexCheck.h"
40#include "ProBoundsPointerArithmeticCheck.h"
41#include "ProTypeConstCastCheck.h"
42#include "ProTypeCstyleCastCheck.h"
43#include "ProTypeMemberInitCheck.h"
44#include "ProTypeReinterpretCastCheck.h"
45#include "ProTypeStaticCastDowncastCheck.h"
46#include "ProTypeUnionAccessCheck.h"
47#include "ProTypeVarargCheck.h"
48#include "RvalueReferenceParamNotMovedCheck.h"
49#include "SlicingCheck.h"
50#include "SpecialMemberFunctionsCheck.h"
51#include "VirtualClassDestructorCheck.h"
52
53namespace clang::tidy {
54namespace cppcoreguidelines {
55
56/// A module containing checks of the C++ Core Guidelines
57class CppCoreGuidelinesModule : public ClangTidyModule {
58public:
59 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
60 CheckFactories.registerCheck<AvoidCapturingLambdaCoroutinesCheck>(
61 CheckName: "cppcoreguidelines-avoid-capturing-lambda-coroutines");
62 CheckFactories.registerCheck<modernize::AvoidCArraysCheck>(
63 CheckName: "cppcoreguidelines-avoid-c-arrays");
64 CheckFactories.registerCheck<AvoidConstOrRefDataMembersCheck>(
65 CheckName: "cppcoreguidelines-avoid-const-or-ref-data-members");
66 CheckFactories.registerCheck<AvoidDoWhileCheck>(
67 CheckName: "cppcoreguidelines-avoid-do-while");
68 CheckFactories.registerCheck<AvoidGotoCheck>(
69 CheckName: "cppcoreguidelines-avoid-goto");
70 CheckFactories.registerCheck<readability::MagicNumbersCheck>(
71 CheckName: "cppcoreguidelines-avoid-magic-numbers");
72 CheckFactories.registerCheck<AvoidNonConstGlobalVariablesCheck>(
73 CheckName: "cppcoreguidelines-avoid-non-const-global-variables");
74 CheckFactories.registerCheck<AvoidReferenceCoroutineParametersCheck>(
75 CheckName: "cppcoreguidelines-avoid-reference-coroutine-parameters");
76 CheckFactories.registerCheck<modernize::UseOverrideCheck>(
77 CheckName: "cppcoreguidelines-explicit-virtual-functions");
78 CheckFactories.registerCheck<InitVariablesCheck>(
79 CheckName: "cppcoreguidelines-init-variables");
80 CheckFactories.registerCheck<InterfacesGlobalInitCheck>(
81 CheckName: "cppcoreguidelines-interfaces-global-init");
82 CheckFactories.registerCheck<modernize::MacroToEnumCheck>(
83 CheckName: "cppcoreguidelines-macro-to-enum");
84 CheckFactories.registerCheck<MacroUsageCheck>(
85 CheckName: "cppcoreguidelines-macro-usage");
86 CheckFactories.registerCheck<MisleadingCaptureDefaultByValueCheck>(
87 CheckName: "cppcoreguidelines-misleading-capture-default-by-value");
88 CheckFactories.registerCheck<MissingStdForwardCheck>(
89 CheckName: "cppcoreguidelines-missing-std-forward");
90 CheckFactories.registerCheck<NarrowingConversionsCheck>(
91 CheckName: "cppcoreguidelines-narrowing-conversions");
92 CheckFactories.registerCheck<NoMallocCheck>(CheckName: "cppcoreguidelines-no-malloc");
93 CheckFactories.registerCheck<NoSuspendWithLockCheck>(
94 CheckName: "cppcoreguidelines-no-suspend-with-lock");
95 CheckFactories.registerCheck<performance::NoexceptDestructorCheck>(
96 CheckName: "cppcoreguidelines-noexcept-destructor");
97 CheckFactories.registerCheck<performance::NoexceptMoveConstructorCheck>(
98 CheckName: "cppcoreguidelines-noexcept-move-operations");
99 CheckFactories.registerCheck<performance::NoexceptSwapCheck>(
100 CheckName: "cppcoreguidelines-noexcept-swap");
101 CheckFactories.registerCheck<misc::NonPrivateMemberVariablesInClassesCheck>(
102 CheckName: "cppcoreguidelines-non-private-member-variables-in-classes");
103 CheckFactories.registerCheck<OwningMemoryCheck>(
104 CheckName: "cppcoreguidelines-owning-memory");
105 CheckFactories.registerCheck<PreferMemberInitializerCheck>(
106 CheckName: "cppcoreguidelines-prefer-member-initializer");
107 CheckFactories.registerCheck<ProBoundsArrayToPointerDecayCheck>(
108 CheckName: "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
109 CheckFactories.registerCheck<ProBoundsConstantArrayIndexCheck>(
110 CheckName: "cppcoreguidelines-pro-bounds-constant-array-index");
111 CheckFactories.registerCheck<ProBoundsPointerArithmeticCheck>(
112 CheckName: "cppcoreguidelines-pro-bounds-pointer-arithmetic");
113 CheckFactories.registerCheck<ProTypeConstCastCheck>(
114 CheckName: "cppcoreguidelines-pro-type-const-cast");
115 CheckFactories.registerCheck<ProTypeCstyleCastCheck>(
116 CheckName: "cppcoreguidelines-pro-type-cstyle-cast");
117 CheckFactories.registerCheck<ProTypeMemberInitCheck>(
118 CheckName: "cppcoreguidelines-pro-type-member-init");
119 CheckFactories.registerCheck<ProTypeReinterpretCastCheck>(
120 CheckName: "cppcoreguidelines-pro-type-reinterpret-cast");
121 CheckFactories.registerCheck<ProTypeStaticCastDowncastCheck>(
122 CheckName: "cppcoreguidelines-pro-type-static-cast-downcast");
123 CheckFactories.registerCheck<ProTypeUnionAccessCheck>(
124 CheckName: "cppcoreguidelines-pro-type-union-access");
125 CheckFactories.registerCheck<ProTypeVarargCheck>(
126 CheckName: "cppcoreguidelines-pro-type-vararg");
127 CheckFactories.registerCheck<RvalueReferenceParamNotMovedCheck>(
128 CheckName: "cppcoreguidelines-rvalue-reference-param-not-moved");
129 CheckFactories.registerCheck<SpecialMemberFunctionsCheck>(
130 CheckName: "cppcoreguidelines-special-member-functions");
131 CheckFactories.registerCheck<SlicingCheck>(CheckName: "cppcoreguidelines-slicing");
132 CheckFactories.registerCheck<modernize::UseDefaultMemberInitCheck>(
133 CheckName: "cppcoreguidelines-use-default-member-init");
134 CheckFactories.registerCheck<misc::UnconventionalAssignOperatorCheck>(
135 CheckName: "cppcoreguidelines-c-copy-assignment-signature");
136 CheckFactories.registerCheck<VirtualClassDestructorCheck>(
137 CheckName: "cppcoreguidelines-virtual-class-destructor");
138 }
139
140 ClangTidyOptions getModuleOptions() override {
141 ClangTidyOptions Options;
142 ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
143
144 Opts["cppcoreguidelines-non-private-member-variables-in-classes."
145 "IgnoreClassesWithAllMemberVariablesBeingPublic"] = "true";
146
147 return Options;
148 }
149};
150
151// Register the LLVMTidyModule using this statically initialized variable.
152static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule>
153 X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.");
154
155} // namespace cppcoreguidelines
156
157// This anchor is used to force the linker to link in the generated object file
158// and thus register the CppCoreGuidelinesModule.
159volatile int CppCoreGuidelinesModuleAnchorSource = 0;
160
161} // namespace clang::tidy
162

source code of clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp