clang-tools  11.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"
28 #include "ProTypeConstCastCheck.h"
29 #include "ProTypeCstyleCastCheck.h"
30 #include "ProTypeMemberInitCheck.h"
34 #include "ProTypeVarargCheck.h"
35 #include "SlicingCheck.h"
37 
38 namespace clang {
39 namespace tidy {
40 namespace cppcoreguidelines {
41 
42 /// A module containing checks of the C++ Core Guidelines
44 public:
45  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
47  "cppcoreguidelines-avoid-c-arrays");
48  CheckFactories.registerCheck<AvoidGotoCheck>(
49  "cppcoreguidelines-avoid-goto");
51  "cppcoreguidelines-avoid-magic-numbers");
53  "cppcoreguidelines-avoid-non-const-global-variables");
55  "cppcoreguidelines-explicit-virtual-functions");
56  CheckFactories.registerCheck<InitVariablesCheck>(
57  "cppcoreguidelines-init-variables");
59  "cppcoreguidelines-interfaces-global-init");
60  CheckFactories.registerCheck<MacroUsageCheck>(
61  "cppcoreguidelines-macro-usage");
63  "cppcoreguidelines-narrowing-conversions");
64  CheckFactories.registerCheck<NoMallocCheck>("cppcoreguidelines-no-malloc");
66  "cppcoreguidelines-non-private-member-variables-in-classes");
67  CheckFactories.registerCheck<OwningMemoryCheck>(
68  "cppcoreguidelines-owning-memory");
70  "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
72  "cppcoreguidelines-pro-bounds-constant-array-index");
74  "cppcoreguidelines-pro-bounds-pointer-arithmetic");
75  CheckFactories.registerCheck<ProTypeConstCastCheck>(
76  "cppcoreguidelines-pro-type-const-cast");
77  CheckFactories.registerCheck<ProTypeCstyleCastCheck>(
78  "cppcoreguidelines-pro-type-cstyle-cast");
79  CheckFactories.registerCheck<ProTypeMemberInitCheck>(
80  "cppcoreguidelines-pro-type-member-init");
82  "cppcoreguidelines-pro-type-reinterpret-cast");
84  "cppcoreguidelines-pro-type-static-cast-downcast");
85  CheckFactories.registerCheck<ProTypeUnionAccessCheck>(
86  "cppcoreguidelines-pro-type-union-access");
87  CheckFactories.registerCheck<ProTypeVarargCheck>(
88  "cppcoreguidelines-pro-type-vararg");
90  "cppcoreguidelines-special-member-functions");
91  CheckFactories.registerCheck<SlicingCheck>("cppcoreguidelines-slicing");
93  "cppcoreguidelines-c-copy-assignment-signature");
94  }
95 
97  ClangTidyOptions Options;
99 
100  Opts["cppcoreguidelines-non-private-member-variables-in-classes."
101  "IgnoreClassesWithAllMemberVariablesBeingPublic"] = "1";
102 
103  Opts["cppcoreguidelines-explicit-virtual-functions."
104  "IgnoreDestructors"] = "1";
105 
106  return Options;
107  }
108 };
109 
110 // Register the LLVMTidyModule using this statically initialized variable.
111 static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule>
112  X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.");
113 
114 } // namespace cppcoreguidelines
115 
116 // This anchor is used to force the linker to link in the generated object file
117 // and thus register the CppCoreGuidelinesModule.
119 
120 } // namespace tidy
121 } // namespace clang
Flags possible initialization order issues of static variables.
Checks for classes where some, but not all, of the special member functions are defined.
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
This check flags all access to members of unions.
Use C++11&#39;s override and remove virtual where applicable.
Non-const global variables hide dependencies and make the dependencies subject to unpredictable chang...
A module containing checks of the C++ Core Guidelines.
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
This checker is concerned with C-style memory management and suggest modern alternatives to it...
Definition: NoMallocCheck.h:25
Contains options for clang-tidy.
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.
A collection of ClangTidyCheckFactory instances.
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
This check flags all instances of const_cast.
Flags slicing (incomplete copying of an object&#39;s state) of member variables or vtable.
Definition: SlicingCheck.h:27
volatile int CppCoreGuidelinesModuleAnchorSource
The usage of goto for control flow is error prone and should be replaced with looping constructs...
This check flags all use of C-style casts that perform a static_cast downcast, const_cast, or reinterpret_cast.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Find C-style array types and recommend to use std::array<> / std::vector<>.
Detects magic numbers, integer and floating point literals embedded in code.
Checks for common use cases for gsl::owner and enforces the unique owner nature of it whenever possib...
Find macro usage that is considered problematic because better language constructs exist for the task...
static ClangTidyModuleRegistry::Add< CppCoreGuidelinesModule > X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.")
Finds declarations of assignment operators with the wrong return and/or argument types and definition...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
Checks for narrowing conversions, e.g: int i = 0; i += 0.1;.
Checks for usages of static_cast, where a base class is downcasted to a derived class.
This check flags all calls to c-style variadic functions and all use of va_arg.
std::map< std::string, ClangTidyValue > OptionMap
This checks that all array subscriptions on static arrays and std::arrays have a constant index and a...
Flags all kinds of pointer arithmetic that have result of pointer type, i.e.