From a704d4bb27354a7ee54b8672808ebae9c13ba806 Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Mon, 12 Oct 2015 20:46:53 +0000 Subject: [clang-tidy] add check cppcoreguidelines-pro-type-static-cast-downcast Summary: This check flags all usages of static_cast, where a base class is casted to a derived class. In those cases, a fixit is provided to convert the cast to a dynamic_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. This rule is part of the "Type safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type2-dont-use-static_cast-downcasts-use-dynamic_cast-instead Depends on D13313 Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13368 llvm-svn: 250098 --- .../clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp') diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp index 130eabe29f1..358bd6ec8fd 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp @@ -12,6 +12,7 @@ #include "../ClangTidyModuleRegistry.h" #include "ProTypeConstCastCheck.h" #include "ProTypeReinterpretCastCheck.h" +#include "ProTypeStaticCastDowncastCheck.h" namespace clang { namespace tidy { @@ -25,6 +26,8 @@ public: "cppcoreguidelines-pro-type-const-cast"); CheckFactories.registerCheck( "cppcoreguidelines-pro-type-reinterpret-cast"); + CheckFactories.registerCheck( + "cppcoreguidelines-pro-type-static-cast-downcast"); } }; -- cgit v1.2.3