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