clang-tools 20.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/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"
24#include "AvoidDoWhileCheck.h"
25#include "AvoidGotoCheck.h"
28#include "InitVariablesCheck.h"
30#include "MacroUsageCheck.h"
34#include "NoMallocCheck.h"
36#include "OwningMemoryCheck.h"
47#include "ProTypeVarargCheck.h"
49#include "SlicingCheck.h"
52
53namespace clang::tidy {
54namespace cppcoreguidelines {
55
56/// A module containing checks of the C++ Core Guidelines
58public:
59 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
61 "cppcoreguidelines-avoid-capturing-lambda-coroutines");
63 "cppcoreguidelines-avoid-c-arrays");
65 "cppcoreguidelines-avoid-const-or-ref-data-members");
66 CheckFactories.registerCheck<AvoidDoWhileCheck>(
67 "cppcoreguidelines-avoid-do-while");
68 CheckFactories.registerCheck<AvoidGotoCheck>(
69 "cppcoreguidelines-avoid-goto");
71 "cppcoreguidelines-avoid-magic-numbers");
73 "cppcoreguidelines-avoid-non-const-global-variables");
75 "cppcoreguidelines-avoid-reference-coroutine-parameters");
77 "cppcoreguidelines-explicit-virtual-functions");
78 CheckFactories.registerCheck<InitVariablesCheck>(
79 "cppcoreguidelines-init-variables");
81 "cppcoreguidelines-interfaces-global-init");
83 "cppcoreguidelines-macro-to-enum");
84 CheckFactories.registerCheck<MacroUsageCheck>(
85 "cppcoreguidelines-macro-usage");
87 "cppcoreguidelines-misleading-capture-default-by-value");
89 "cppcoreguidelines-missing-std-forward");
91 "cppcoreguidelines-narrowing-conversions");
92 CheckFactories.registerCheck<NoMallocCheck>("cppcoreguidelines-no-malloc");
94 "cppcoreguidelines-no-suspend-with-lock");
96 "cppcoreguidelines-noexcept-destructor");
98 "cppcoreguidelines-noexcept-move-operations");
100 "cppcoreguidelines-noexcept-swap");
102 "cppcoreguidelines-non-private-member-variables-in-classes");
103 CheckFactories.registerCheck<OwningMemoryCheck>(
104 "cppcoreguidelines-owning-memory");
106 "cppcoreguidelines-prefer-member-initializer");
108 "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
110 "cppcoreguidelines-pro-bounds-constant-array-index");
112 "cppcoreguidelines-pro-bounds-pointer-arithmetic");
113 CheckFactories.registerCheck<ProTypeConstCastCheck>(
114 "cppcoreguidelines-pro-type-const-cast");
116 "cppcoreguidelines-pro-type-cstyle-cast");
118 "cppcoreguidelines-pro-type-member-init");
120 "cppcoreguidelines-pro-type-reinterpret-cast");
122 "cppcoreguidelines-pro-type-static-cast-downcast");
124 "cppcoreguidelines-pro-type-union-access");
125 CheckFactories.registerCheck<ProTypeVarargCheck>(
126 "cppcoreguidelines-pro-type-vararg");
128 "cppcoreguidelines-rvalue-reference-param-not-moved");
130 "cppcoreguidelines-special-member-functions");
131 CheckFactories.registerCheck<SlicingCheck>("cppcoreguidelines-slicing");
133 "cppcoreguidelines-use-default-member-init");
135 "cppcoreguidelines-c-copy-assignment-signature");
137 "cppcoreguidelines-virtual-class-destructor");
138 }
139
141 ClangTidyOptions Options;
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.
160
161} // namespace clang::tidy
int X
A collection of ClangTidyCheckFactory instances.
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Flags C++20 coroutine lambdas with non-empty capture lists that may cause use-after-free errors and s...
Const-qualified or reference data members in classes should be avoided, as they make the class non-co...
do-while loops are less readable than plan while loops, and can lead to subtle bugs.
The usage of goto for control flow is error prone and should be replaced with looping constructs.
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.
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Flags possible initialization order issues of static variables.
Find macro usage that is considered problematic because better language constructs exist for the task...
Warns when lambda specify a by-value capture default and capture this.
Warns when a function accepting a forwarding reference does anything besides forwarding (with std::fo...
Checks for narrowing conversions, e.g: int i = 0; i += 0.1;.
This checker is concerned with C-style memory management and suggest modern alternatives to it.
Definition: NoMallocCheck.h:23
Flag coroutines that suspend while any lock guard is alive.
Checks for common use cases for gsl::owner and enforces the unique owner nature of it whenever possib...
Finds member initializations in the constructor body which can be placed into the initialization list...
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.
Imposes limitations on the use of const_cast within C++ code.
This check flags all use of C-style casts that perform a static_cast downcast, const_cast,...
Checks for usages of static_cast, where a base class is downcasted to a derived class.
This check flags all access to members of unions.
This check flags all calls to c-style variadic functions and all use of va_arg.
Warns when an rvalue reference function parameter is never moved within the function body.
Flags slicing (incomplete copying of an object's state) of member variables or vtable.
Definition: SlicingCheck.h:25
Checks for classes where some, but not all, of the special member functions are defined.
Finds base classes whose destructor is neither public and virtual nor protected and non-virtual.
This checker finds classes that not only contain the data (non-static member variables),...
Finds declarations of assignment operators with the wrong return and/or argument types and definition...
Find C-style array types and recommend to use std::array<> / std::vector<>.
Replaces groups of related macros with an unscoped anonymous enum.
Convert a default constructor's member initializers into default member initializers.
Use C++11's override and remove virtual where applicable.
The check flags destructors not marked with noexcept or marked with noexcept(expr) where expr evaluat...
The check flags user-defined move constructors and assignment operators not marked with noexcept or m...
The check flags swap functions not marked with noexcept or marked with noexcept(expr) where expr eval...
Detects magic numbers, integer and floating point literals embedded in code.
volatile int CppCoreGuidelinesModuleAnchorSource
Contains options for clang-tidy.
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
llvm::StringMap< ClangTidyValue > OptionMap