clang-tools 8.0.0

CppCoreGuidelinesTidyModule.cpp
Go to the documentation of this file.
1 //===--- CppCoreGuidelinesModule.cpp - clang-tidy -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "../ClangTidy.h"
11 #include "../ClangTidyModule.h"
12 #include "../ClangTidyModuleRegistry.h"
13 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
14 #include "../misc/UnconventionalAssignOperatorCheck.h"
15 #include "../modernize/AvoidCArraysCheck.h"
16 #include "../readability/MagicNumbersCheck.h"
17 #include "AvoidGotoCheck.h"
18 #include "InterfacesGlobalInitCheck.h"
19 #include "MacroUsageCheck.h"
20 #include "NarrowingConversionsCheck.h"
21 #include "NoMallocCheck.h"
22 #include "OwningMemoryCheck.h"
23 #include "ProBoundsArrayToPointerDecayCheck.h"
24 #include "ProBoundsConstantArrayIndexCheck.h"
25 #include "ProBoundsPointerArithmeticCheck.h"
26 #include "ProTypeConstCastCheck.h"
27 #include "ProTypeCstyleCastCheck.h"
28 #include "ProTypeMemberInitCheck.h"
29 #include "ProTypeReinterpretCastCheck.h"
30 #include "ProTypeStaticCastDowncastCheck.h"
31 #include "ProTypeUnionAccessCheck.h"
32 #include "ProTypeVarargCheck.h"
33 #include "SlicingCheck.h"
34 #include "SpecialMemberFunctionsCheck.h"
35
36 namespace clang {
37 namespace tidy {
38 namespace cppcoreguidelines {
39
40 /// A module containing checks of the C++ Core Guidelines
41 class CppCoreGuidelinesModule : public ClangTidyModule {
42 public:
43 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
44 CheckFactories.registerCheck<modernize::AvoidCArraysCheck>(
45 "cppcoreguidelines-avoid-c-arrays");
46 CheckFactories.registerCheck<AvoidGotoCheck>(
47 "cppcoreguidelines-avoid-goto");
48 CheckFactories.registerCheck<readability::MagicNumbersCheck>(
49 "cppcoreguidelines-avoid-magic-numbers");
50 CheckFactories.registerCheck<InterfacesGlobalInitCheck>(
51 "cppcoreguidelines-interfaces-global-init");
52 CheckFactories.registerCheck<MacroUsageCheck>(
53 "cppcoreguidelines-macro-usage");
54 CheckFactories.registerCheck<NarrowingConversionsCheck>(
55 "cppcoreguidelines-narrowing-conversions");
56 CheckFactories.registerCheck<NoMallocCheck>("cppcoreguidelines-no-malloc");
57 CheckFactories.registerCheck<misc::NonPrivateMemberVariablesInClassesCheck>(
58 "cppcoreguidelines-non-private-member-variables-in-classes");
59 CheckFactories.registerCheck<OwningMemoryCheck>(
60 "cppcoreguidelines-owning-memory");
61 CheckFactories.registerCheck<ProBoundsArrayToPointerDecayCheck>(
62 "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
63 CheckFactories.registerCheck<ProBoundsConstantArrayIndexCheck>(
64 "cppcoreguidelines-pro-bounds-constant-array-index");
65 CheckFactories.registerCheck<ProBoundsPointerArithmeticCheck>(
66 "cppcoreguidelines-pro-bounds-pointer-arithmetic");
67 CheckFactories.registerCheck<ProTypeConstCastCheck>(
68 "cppcoreguidelines-pro-type-const-cast");
69 CheckFactories.registerCheck<ProTypeCstyleCastCheck>(
70 "cppcoreguidelines-pro-type-cstyle-cast");
71 CheckFactories.registerCheck<ProTypeMemberInitCheck>(
72 "cppcoreguidelines-pro-type-member-init");
73 CheckFactories.registerCheck<ProTypeReinterpretCastCheck>(
74 "cppcoreguidelines-pro-type-reinterpret-cast");
75 CheckFactories.registerCheck<ProTypeStaticCastDowncastCheck>(
76 "cppcoreguidelines-pro-type-static-cast-downcast");
77 CheckFactories.registerCheck<ProTypeUnionAccessCheck>(
78 "cppcoreguidelines-pro-type-union-access");
79 CheckFactories.registerCheck<ProTypeVarargCheck>(
80 "cppcoreguidelines-pro-type-vararg");
81 CheckFactories.registerCheck<SpecialMemberFunctionsCheck>(
82 "cppcoreguidelines-special-member-functions");
83 CheckFactories.registerCheck<SlicingCheck>("cppcoreguidelines-slicing");
84 CheckFactories.registerCheck<misc::UnconventionalAssignOperatorCheck>(
85 "cppcoreguidelines-c-copy-assignment-signature");
86 }
87
88 ClangTidyOptions getModuleOptions() override {
89 ClangTidyOptions Options;
90 ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
91
92 Opts["cppcoreguidelines-non-private-member-variables-in-classes."
93 "IgnoreClassesWithAllMemberVariablesBeingPublic"] = "1";
94
95 return Options;
96 }
97 };
98
99 // Register the LLVMTidyModule using this statically initialized variable.
100 static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule>
101 X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.");
102
103 } // namespace cppcoreguidelines
104
105 // This anchor is used to force the linker to link in the generated object file
106 // and thus register the CppCoreGuidelinesModule.
107 volatile int CppCoreGuidelinesModuleAnchorSource = 0;
108
109 } // namespace tidy
110 } // namespace clang
InterfacesGlobalInitCheck.h
clang::tidy::cppcoreguidelines::InterfacesGlobalInitCheck
Flags possible initialization order issues of static variables.
Definition: InterfacesGlobalInitCheck.h:23
clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck
Checks for classes where some, but not all, of the special member functions are defined.
Definition: SpecialMemberFunctionsCheck.h:26
ProBoundsConstantArrayIndexCheck.h
clang::tidy::cppcoreguidelines::ProTypeUnionAccessCheck
This check flags all access to members of unions.
Definition: ProTypeUnionAccessCheck.h:24
SpecialMemberFunctionsCheck.h
NarrowingConversionsCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
clang::tidy::cppcoreguidelines::ProTypeMemberInitCheck
Implements C++ Core Guidelines Type.6.
Definition: ProTypeMemberInitCheck.h:34
clang::tidy::cppcoreguidelines::CppCoreGuidelinesModule
A module containing checks of the C++ Core Guidelines.
Definition: CppCoreGuidelinesTidyModule.cpp:41
clang::tidy::cppcoreguidelines::CppCoreGuidelinesModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: CppCoreGuidelinesTidyModule.cpp:88
clang::tidy::cppcoreguidelines::NoMallocCheck
This checker is concerned with C-style memory management and suggest modern alternatives to it...
Definition: NoMallocCheck.h:28
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:51
clang::tidy::misc::NonPrivateMemberVariablesInClassesCheck
This checker 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.
Definition: NonPrivateMemberVariablesInClassesCheck.h:30
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:27
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:101
clang::tidy::cppcoreguidelines::ProTypeConstCastCheck
This check flags all instances of const_cast.
Definition: ProTypeConstCastCheck.h:23
ProTypeUnionAccessCheck.h
clang::tidy::cppcoreguidelines::SlicingCheck
Flags slicing (incomplete copying of an object&#39;s state) of member variables or vtable.
Definition: SlicingCheck.h:28
ProTypeStaticCastDowncastCheck.h
NoMallocCheck.h
SlicingCheck.h
clang::tidy::CppCoreGuidelinesModuleAnchorSource
volatile int CppCoreGuidelinesModuleAnchorSource
Definition: CppCoreGuidelinesTidyModule.cpp:107
clang::tidy::cppcoreguidelines::AvoidGotoCheck
The usage of goto for control flow is error prone and should be replaced with looping constructs...
Definition: AvoidGotoCheck.h:24
clang::tidy::cppcoreguidelines::ProTypeCstyleCastCheck
This check flags all use of C-style casts that perform a static_cast downcast, const_cast, or reinterpret_cast.
Definition: ProTypeCstyleCastCheck.h:24
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:84
ProTypeCstyleCastCheck.h
OwningMemoryCheck.h
clang::tidy::modernize::AvoidCArraysCheck
Find C-style array types and recommend to use std::array<> / std::vector<>.
Definition: AvoidCArraysCheck.h:23
clang::tidy::readability::MagicNumbersCheck
Detects magic numbers, integer and floating point literals embedded in code.
Definition: MagicNumbersCheck.h:26
clang::tidy::cppcoreguidelines::ProTypeReinterpretCastCheck
Flags all occurrences of reinterpret_cast.
Definition: ProTypeReinterpretCastCheck.h:23
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:24
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:98
MacroUsageCheck.h
clang::tidy::cppcoreguidelines::MacroUsageCheck
Find macro usage that is considered problematic because better language constructs exist for the task...
Definition: MacroUsageCheck.h:26
ProBoundsArrayToPointerDecayCheck.h
ProTypeReinterpretCastCheck.h
ProTypeVarargCheck.h
clang::tidy::cppcoreguidelines::X
static ClangTidyModuleRegistry::Add< CppCoreGuidelinesModule > X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.")
clang::tidy::misc::UnconventionalAssignOperatorCheck
Finds declarations of assignment operators with the wrong return and/or argument types and definition...
Definition: UnconventionalAssignOperatorCheck.h:30
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
ProTypeMemberInitCheck.h
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:43
clang::tidy::cppcoreguidelines::NarrowingConversionsCheck
Checks for narrowing conversions, e.g: int i = 0; i += 0.1;.
Definition: NarrowingConversionsCheck.h:25
clang::tidy::cppcoreguidelines::ProBoundsArrayToPointerDecayCheck
This check flags all array to pointer decays.
Definition: ProBoundsArrayToPointerDecayCheck.h:23
clang::tidy::cppcoreguidelines::ProTypeStaticCastDowncastCheck
Checks for usages of static_cast, where a base class is downcasted to a derived class.
Definition: ProTypeStaticCastDowncastCheck.h:24
clang::tidy::cppcoreguidelines::ProTypeVarargCheck
This check flags all calls to c-style variadic functions and all use of va_arg.
Definition: ProTypeVarargCheck.h:24
ProBoundsPointerArithmeticCheck.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:25
ProTypeConstCastCheck.h
AvoidGotoCheck.h
clang::tidy::cppcoreguidelines::ProBoundsPointerArithmeticCheck
Flags all kinds of pointer arithmetic that have result of pointer type, i.e.
Definition: ProBoundsPointerArithmeticCheck.h:25