2015-10-06 21:31:00 +08:00
|
|
|
//===--- CppCoreGuidelinesModule.cpp - clang-tidy -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
|
|
|
#include "../ClangTidyModule.h"
|
|
|
|
#include "../ClangTidyModuleRegistry.h"
|
2016-05-04 20:02:22 +08:00
|
|
|
#include "../misc/UnconventionalAssignOperatorCheck.h"
|
2016-04-08 17:51:06 +08:00
|
|
|
#include "InterfacesGlobalInitCheck.h"
|
2015-10-27 05:56:02 +08:00
|
|
|
#include "ProBoundsArrayToPointerDecayCheck.h"
|
2015-12-14 06:08:26 +08:00
|
|
|
#include "ProBoundsConstantArrayIndexCheck.h"
|
2015-10-13 05:53:19 +08:00
|
|
|
#include "ProBoundsPointerArithmeticCheck.h"
|
2015-10-07 20:24:57 +08:00
|
|
|
#include "ProTypeConstCastCheck.h"
|
[clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast
Summary:
This check flags all use of c-style casts that perform a static_cast
downcast, const_cast, or reinterpret_cast.
Use of these casts can violate type safety and cause the program to
access a
variable that is actually of type X to be accessed as if it were of an
unrelated type Z. Note that a C-style (T)expression cast means to
perform
the first of the following that is possible: a const_cast, a
static_cast, a
static_cast followed by a const_cast, a reinterpret_cast, or a
reinterpret_cast followed by a const_cast. This rule bans (T)expression
only when used to perform an unsafe cast.
This rule is part of the "Type safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type4-dont-use-c-style-texpression-casts-that-would-perform-a-static_cast-downcast-const_cast-or-reinterpret_cast.
Reviewers: alexfh, sbenza, bkramer, aaron.ballman
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D14096
llvm-svn: 252425
2015-11-09 05:10:39 +08:00
|
|
|
#include "ProTypeCstyleCastCheck.h"
|
2016-02-15 12:27:56 +08:00
|
|
|
#include "ProTypeMemberInitCheck.h"
|
2015-10-06 21:31:00 +08:00
|
|
|
#include "ProTypeReinterpretCastCheck.h"
|
2015-10-13 04:46:53 +08:00
|
|
|
#include "ProTypeStaticCastDowncastCheck.h"
|
2015-10-17 02:46:30 +08:00
|
|
|
#include "ProTypeUnionAccessCheck.h"
|
2015-10-22 04:09:02 +08:00
|
|
|
#include "ProTypeVarargCheck.h"
|
2016-07-22 21:45:00 +08:00
|
|
|
#include "SlicingCheck.h"
|
2015-10-06 21:31:00 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace cppcoreguidelines {
|
|
|
|
|
2015-10-12 06:55:29 +08:00
|
|
|
/// A module containing checks of the C++ Core Guidelines
|
2015-10-06 21:31:00 +08:00
|
|
|
class CppCoreGuidelinesModule : public ClangTidyModule {
|
|
|
|
public:
|
|
|
|
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
2016-04-08 17:51:06 +08:00
|
|
|
CheckFactories.registerCheck<InterfacesGlobalInitCheck>(
|
|
|
|
"cppcoreguidelines-interfaces-global-init");
|
2015-10-27 05:56:02 +08:00
|
|
|
CheckFactories.registerCheck<ProBoundsArrayToPointerDecayCheck>(
|
|
|
|
"cppcoreguidelines-pro-bounds-array-to-pointer-decay");
|
2015-12-14 06:08:26 +08:00
|
|
|
CheckFactories.registerCheck<ProBoundsConstantArrayIndexCheck>(
|
|
|
|
"cppcoreguidelines-pro-bounds-constant-array-index");
|
2015-10-13 05:53:19 +08:00
|
|
|
CheckFactories.registerCheck<ProBoundsPointerArithmeticCheck>(
|
|
|
|
"cppcoreguidelines-pro-bounds-pointer-arithmetic");
|
2015-10-07 20:24:57 +08:00
|
|
|
CheckFactories.registerCheck<ProTypeConstCastCheck>(
|
|
|
|
"cppcoreguidelines-pro-type-const-cast");
|
[clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast
Summary:
This check flags all use of c-style casts that perform a static_cast
downcast, const_cast, or reinterpret_cast.
Use of these casts can violate type safety and cause the program to
access a
variable that is actually of type X to be accessed as if it were of an
unrelated type Z. Note that a C-style (T)expression cast means to
perform
the first of the following that is possible: a const_cast, a
static_cast, a
static_cast followed by a const_cast, a reinterpret_cast, or a
reinterpret_cast followed by a const_cast. This rule bans (T)expression
only when used to perform an unsafe cast.
This rule is part of the "Type safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type4-dont-use-c-style-texpression-casts-that-would-perform-a-static_cast-downcast-const_cast-or-reinterpret_cast.
Reviewers: alexfh, sbenza, bkramer, aaron.ballman
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D14096
llvm-svn: 252425
2015-11-09 05:10:39 +08:00
|
|
|
CheckFactories.registerCheck<ProTypeCstyleCastCheck>(
|
|
|
|
"cppcoreguidelines-pro-type-cstyle-cast");
|
2016-02-15 12:27:56 +08:00
|
|
|
CheckFactories.registerCheck<ProTypeMemberInitCheck>(
|
|
|
|
"cppcoreguidelines-pro-type-member-init");
|
2015-10-06 21:31:00 +08:00
|
|
|
CheckFactories.registerCheck<ProTypeReinterpretCastCheck>(
|
|
|
|
"cppcoreguidelines-pro-type-reinterpret-cast");
|
2015-10-13 04:46:53 +08:00
|
|
|
CheckFactories.registerCheck<ProTypeStaticCastDowncastCheck>(
|
|
|
|
"cppcoreguidelines-pro-type-static-cast-downcast");
|
2015-10-17 02:46:30 +08:00
|
|
|
CheckFactories.registerCheck<ProTypeUnionAccessCheck>(
|
|
|
|
"cppcoreguidelines-pro-type-union-access");
|
2015-10-22 04:09:02 +08:00
|
|
|
CheckFactories.registerCheck<ProTypeVarargCheck>(
|
|
|
|
"cppcoreguidelines-pro-type-vararg");
|
2016-07-22 21:45:00 +08:00
|
|
|
CheckFactories.registerCheck<SlicingCheck>(
|
|
|
|
"cppcoreguidelines-slicing");
|
2016-05-04 20:02:22 +08:00
|
|
|
CheckFactories.registerCheck<misc::UnconventionalAssignOperatorCheck>(
|
2015-10-13 23:24:33 +08:00
|
|
|
"cppcoreguidelines-c-copy-assignment-signature");
|
2015-10-06 21:31:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Register the LLVMTidyModule using this statically initialized variable.
|
|
|
|
static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule>
|
|
|
|
X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.");
|
|
|
|
|
|
|
|
} // namespace cppcoreguidelines
|
|
|
|
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the CppCoreGuidelinesModule.
|
|
|
|
volatile int CppCoreGuidelinesModuleAnchorSource = 0;
|
|
|
|
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|