From b785407c2835a7870f2909c218cc5d3589f5d778 Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Fri, 16 Oct 2015 18:46:30 +0000 Subject: [clang-tidy] add check cppcoreguidelines-pro-type-union-access Summary: This check flags all access to members of unions. Passing unions as a whole is not flagged. Reading from a union member assumes that member was the last one written, and writing to a union member assumes another member with a nontrivial destructor had its destructor called. This is fragile because it cannot generally be enforced to be safe in the language and so relies on programmer discipline to get it right. This rule is part of the "Type safety" profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type7-avoid-accessing-members-of-raw-unions-prefer-variant-instead Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13784 llvm-svn: 250537 --- .../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 0d239ff1b98..3d517902660 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp @@ -16,6 +16,7 @@ #include "ProTypeConstCastCheck.h" #include "ProTypeReinterpretCastCheck.h" #include "ProTypeStaticCastDowncastCheck.h" +#include "ProTypeUnionAccessCheck.h" namespace clang { namespace tidy { @@ -35,6 +36,8 @@ public: "cppcoreguidelines-pro-type-reinterpret-cast"); CheckFactories.registerCheck( "cppcoreguidelines-pro-type-static-cast-downcast"); + CheckFactories.registerCheck( + "cppcoreguidelines-pro-type-union-access"); CheckFactories.registerCheck( "cppcoreguidelines-c-copy-assignment-signature"); } -- cgit v1.2.3