clang-tools  10.0.0svn
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 for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
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/UseOverrideCheck.h"
16 #include "../readability/MagicNumbersCheck.h"
17 #include "AvoidGotoCheck.h"
18 #include "InitVariablesCheck.h"
20 #include "MacroUsageCheck.h"
22 #include "NoMallocCheck.h"
23 #include "OwningMemoryCheck.h"
27 #include "ProTypeConstCastCheck.h"
28 #include "ProTypeCstyleCastCheck.h"
29 #include "ProTypeMemberInitCheck.h"
33 #include "ProTypeVarargCheck.h"
34 #include "SlicingCheck.h"
37 namespace clang {
38 namespace tidy {
39 namespace cppcoreguidelines {
41 /// A module containing checks of the C++ Core Guidelines
43 public:
44  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
46  "cppcoreguidelines-avoid-c-arrays");
47  CheckFactories.registerCheck<AvoidGotoCheck>(
48  "cppcoreguidelines-avoid-goto");
50  "cppcoreguidelines-avoid-magic-numbers");
52  "cppcoreguidelines-explicit-virtual-functions");
53  CheckFactories.registerCheck<InitVariablesCheck>(
54  "cppcoreguidelines-init-variables");
56  "cppcoreguidelines-interfaces-global-init");
57  CheckFactories.registerCheck<MacroUsageCheck>(
58  "cppcoreguidelines-macro-usage");
60  "cppcoreguidelines-narrowing-conversions");
61  CheckFactories.registerCheck<NoMallocCheck>("cppcoreguidelines-no-malloc");
63  "cppcoreguidelines-non-private-member-variables-in-classes");
64  CheckFactories.registerCheck<OwningMemoryCheck>(
65  "cppcoreguidelines-owning-memory");
67  "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
69  "cppcoreguidelines-pro-bounds-constant-array-index");
71  "cppcoreguidelines-pro-bounds-pointer-arithmetic");
72  CheckFactories.registerCheck<ProTypeConstCastCheck>(
73  "cppcoreguidelines-pro-type-const-cast");
74  CheckFactories.registerCheck<ProTypeCstyleCastCheck>(
75  "cppcoreguidelines-pro-type-cstyle-cast");
76  CheckFactories.registerCheck<ProTypeMemberInitCheck>(
77  "cppcoreguidelines-pro-type-member-init");
79  "cppcoreguidelines-pro-type-reinterpret-cast");
81  "cppcoreguidelines-pro-type-static-cast-downcast");
82  CheckFactories.registerCheck<ProTypeUnionAccessCheck>(
83  "cppcoreguidelines-pro-type-union-access");
84  CheckFactories.registerCheck<ProTypeVarargCheck>(
85  "cppcoreguidelines-pro-type-vararg");
87  "cppcoreguidelines-special-member-functions");
88  CheckFactories.registerCheck<SlicingCheck>("cppcoreguidelines-slicing");
90  "cppcoreguidelines-c-copy-assignment-signature");
91  }
94  ClangTidyOptions Options;
97  Opts["cppcoreguidelines-non-private-member-variables-in-classes."
98  "IgnoreClassesWithAllMemberVariablesBeingPublic"] = "1";
100  Opts["cppcoreguidelines-explicit-virtual-functions."
101  "IgnoreDestructors"] = "1";
103  return Options;
104  }
105 };
107 // Register the LLVMTidyModule using this statically initialized variable.
108 static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule>
109  X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.");
111 } // namespace cppcoreguidelines
113 // This anchor is used to force the linker to link in the generated object file
114 // and thus register the CppCoreGuidelinesModule.
117 } // namespace tidy
118 } // 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.
This check flags all access to members of unions.
Use C++11&#39;s override and remove virtual where applicable.
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
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:27
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...
std::map< std::string, std::string > OptionMap
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.
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.