clang-tools  14.0.0git
CppCoreGuidelinesTidyModule.cpp
Go to the documentation of this file.
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/UseOverrideCheck.h"
16 #include "../readability/MagicNumbersCheck.h"
17 #include "AvoidGotoCheck.h"
19 #include "InitVariablesCheck.h"
21 #include "MacroUsageCheck.h"
23 #include "NoMallocCheck.h"
24 #include "OwningMemoryCheck.h"
29 #include "ProTypeConstCastCheck.h"
30 #include "ProTypeCstyleCastCheck.h"
31 #include "ProTypeMemberInitCheck.h"
35 #include "ProTypeVarargCheck.h"
36 #include "SlicingCheck.h"
39 
40 namespace clang {
41 namespace tidy {
42 namespace cppcoreguidelines {
43 
44 /// A module containing checks of the C++ Core Guidelines
46 public:
47  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
49  "cppcoreguidelines-avoid-c-arrays");
50  CheckFactories.registerCheck<AvoidGotoCheck>(
51  "cppcoreguidelines-avoid-goto");
53  "cppcoreguidelines-avoid-magic-numbers");
55  "cppcoreguidelines-avoid-non-const-global-variables");
57  "cppcoreguidelines-explicit-virtual-functions");
58  CheckFactories.registerCheck<InitVariablesCheck>(
59  "cppcoreguidelines-init-variables");
61  "cppcoreguidelines-interfaces-global-init");
62  CheckFactories.registerCheck<MacroUsageCheck>(
63  "cppcoreguidelines-macro-usage");
65  "cppcoreguidelines-narrowing-conversions");
66  CheckFactories.registerCheck<NoMallocCheck>("cppcoreguidelines-no-malloc");
68  "cppcoreguidelines-non-private-member-variables-in-classes");
69  CheckFactories.registerCheck<OwningMemoryCheck>(
70  "cppcoreguidelines-owning-memory");
72  "cppcoreguidelines-prefer-member-initializer");
74  "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
76  "cppcoreguidelines-pro-bounds-constant-array-index");
78  "cppcoreguidelines-pro-bounds-pointer-arithmetic");
79  CheckFactories.registerCheck<ProTypeConstCastCheck>(
80  "cppcoreguidelines-pro-type-const-cast");
81  CheckFactories.registerCheck<ProTypeCstyleCastCheck>(
82  "cppcoreguidelines-pro-type-cstyle-cast");
83  CheckFactories.registerCheck<ProTypeMemberInitCheck>(
84  "cppcoreguidelines-pro-type-member-init");
86  "cppcoreguidelines-pro-type-reinterpret-cast");
88  "cppcoreguidelines-pro-type-static-cast-downcast");
89  CheckFactories.registerCheck<ProTypeUnionAccessCheck>(
90  "cppcoreguidelines-pro-type-union-access");
91  CheckFactories.registerCheck<ProTypeVarargCheck>(
92  "cppcoreguidelines-pro-type-vararg");
94  "cppcoreguidelines-special-member-functions");
95  CheckFactories.registerCheck<SlicingCheck>("cppcoreguidelines-slicing");
97  "cppcoreguidelines-c-copy-assignment-signature");
99  "cppcoreguidelines-virtual-class-destructor");
100  }
101 
103  ClangTidyOptions Options;
105 
106  Opts["cppcoreguidelines-non-private-member-variables-in-classes."
107  "IgnoreClassesWithAllMemberVariablesBeingPublic"] = "true";
108 
109  return Options;
110  }
111 };
112 
113 // Register the LLVMTidyModule using this statically initialized variable.
114 static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule>
115  X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.");
116 
117 } // namespace cppcoreguidelines
118 
119 // This anchor is used to force the linker to link in the generated object file
120 // and thus register the CppCoreGuidelinesModule.
122 
123 } // namespace tidy
124 } // namespace clang
clang::tidy::cppcoreguidelines::CppCoreGuidelinesModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Definition: CppCoreGuidelinesTidyModule.cpp:47
SpecialMemberFunctionsCheck.h
AvoidNonConstGlobalVariablesCheck.h
InterfacesGlobalInitCheck.h
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck
Checks for classes where some, but not all, of the special member functions are defined.
Definition: SpecialMemberFunctionsCheck.h:25
clang::tidy::cppcoreguidelines::InterfacesGlobalInitCheck
Flags possible initialization order issues of static variables.
Definition: InterfacesGlobalInitCheck.h:22
clang::tidy::cppcoreguidelines::ProTypeStaticCastDowncastCheck
Checks for usages of static_cast, where a base class is downcasted to a derived class.
Definition: ProTypeStaticCastDowncastCheck.h:23
ProTypeVarargCheck.h
clang::tidy::cppcoreguidelines::NoMallocCheck
This checker is concerned with C-style memory management and suggest modern alternatives to it.
Definition: NoMallocCheck.h:25
clang::tidy::cppcoreguidelines::CppCoreGuidelinesModule
A module containing checks of the C++ Core Guidelines.
Definition: CppCoreGuidelinesTidyModule.cpp:45
AvoidGotoCheck.h
clang::tidy::cppcoreguidelines::AvoidGotoCheck
The usage of goto for control flow is error prone and should be replaced with looping constructs.
Definition: AvoidGotoCheck.h:23
NarrowingConversionsCheck.h
ProTypeConstCastCheck.h
clang::tidy::cppcoreguidelines::X
static ClangTidyModuleRegistry::Add< CppCoreGuidelinesModule > X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.")
InitVariablesCheck.h
clang::tidy::misc::NonPrivateMemberVariablesInClassesCheck
This checker finds classes that not only contain the data (non-static member variables),...
Definition: NonPrivateMemberVariablesInClassesCheck.h:29
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:118
clang::tidy::cppcoreguidelines::CppCoreGuidelinesModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: CppCoreGuidelinesTidyModule.cpp:102
ProTypeUnionAccessCheck.h
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:50
clang::tidy::misc::UnconventionalAssignOperatorCheck
Finds declarations of assignment operators with the wrong return and/or argument types and definition...
Definition: UnconventionalAssignOperatorCheck.h:29
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:28
clang::tidy::cppcoreguidelines::VirtualClassDestructorCheck
Finds base classes whose destructor is neither public and virtual nor protected and non-virtual.
Definition: VirtualClassDestructorCheck.h:24
ProBoundsArrayToPointerDecayCheck.h
clang::tidy::cppcoreguidelines::ProTypeReinterpretCastCheck
Flags all occurrences of reinterpret_cast.
Definition: ProTypeReinterpretCastCheck.h:22
clang::tidy::cppcoreguidelines::PreferMemberInitializerCheck
Finds member initializations in the constructor body which can be placed into the initialization list...
Definition: PreferMemberInitializerCheck.h:23
clang::tidy::cppcoreguidelines::NarrowingConversionsCheck
Checks for narrowing conversions, e.g: int i = 0; i += 0.1;.
Definition: NarrowingConversionsCheck.h:24
ProTypeMemberInitCheck.h
clang::tidy::cppcoreguidelines::ProTypeMemberInitCheck
Implements C++ Core Guidelines Type.6.
Definition: ProTypeMemberInitCheck.h:34
clang::tidy::cppcoreguidelines::ProBoundsArrayToPointerDecayCheck
This check flags all array to pointer decays.
Definition: ProBoundsArrayToPointerDecayCheck.h:22
OwningMemoryCheck.h
clang::tidy::cppcoreguidelines::MacroUsageCheck
Find macro usage that is considered problematic because better language constructs exist for the task...
Definition: MacroUsageCheck.h:26
SlicingCheck.h
clang::tidy::CppCoreGuidelinesModuleAnchorSource
volatile int CppCoreGuidelinesModuleAnchorSource
Definition: CppCoreGuidelinesTidyModule.cpp:121
ProTypeReinterpretCastCheck.h
clang::tidy::cppcoreguidelines::InitVariablesCheck
Find uninitialized local variables.
Definition: InitVariablesCheck.h:24
clang::tidy::modernize::UseOverrideCheck
Use C++11's override and remove virtual where applicable.
Definition: UseOverrideCheck.h:19
ProBoundsPointerArithmeticCheck.h
clang::tidy::cppcoreguidelines::SlicingCheck
Flags slicing (incomplete copying of an object's state) of member variables or vtable.
Definition: SlicingCheck.h:27
ProTypeStaticCastDowncastCheck.h
clang::tidy::readability::MagicNumbersCheck
Detects magic numbers, integer and floating point literals embedded in code.
Definition: MagicNumbersCheck.h:25
clang::tidy::cppcoreguidelines::AvoidNonConstGlobalVariablesCheck
Non-const global variables hide dependencies and make the dependencies subject to unpredictable chang...
Definition: AvoidNonConstGlobalVariablesCheck.h:23
PreferMemberInitializerCheck.h
VirtualClassDestructorCheck.h
clang::tidy::cppcoreguidelines::ProTypeUnionAccessCheck
This check flags all access to members of unions.
Definition: ProTypeUnionAccessCheck.h:23
NoMallocCheck.h
ProTypeCstyleCastCheck.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::cppcoreguidelines::ProTypeVarargCheck
This check flags all calls to c-style variadic functions and all use of va_arg.
Definition: ProTypeVarargCheck.h:23
clang::tidy::cppcoreguidelines::ProBoundsPointerArithmeticCheck
Flags all kinds of pointer arithmetic that have result of pointer type, i.e.
Definition: ProBoundsPointerArithmeticCheck.h:24
ProBoundsConstantArrayIndexCheck.h
clang::tidy::cppcoreguidelines::ProTypeCstyleCastCheck
This check flags all use of C-style casts that perform a static_cast downcast, const_cast,...
Definition: ProTypeCstyleCastCheck.h:23
MacroUsageCheck.h
clang::tidy::cppcoreguidelines::ProBoundsConstantArrayIndexCheck
This checks that all array subscriptions on static arrays and std::arrays have a constant index and a...
Definition: ProBoundsConstantArrayIndexCheck.h:24
clang::tidy::cppcoreguidelines::ProTypeConstCastCheck
This check flags all instances of const_cast.
Definition: ProTypeConstCastCheck.h:22
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:81
clang::tidy::cppcoreguidelines::OwningMemoryCheck
Checks for common use cases for gsl::owner and enforces the unique owner nature of it whenever possib...
Definition: OwningMemoryCheck.h:23
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
clang::tidy::modernize::AvoidCArraysCheck
Find C-style array types and recommend to use std::array<> / std::vector<>.
Definition: AvoidCArraysCheck.h:22