diff options
author | Matthias Gehre <M.Gehre@gmx.de> | 2015-10-16 18:46:30 +0000 |
---|---|---|
committer | Matthias Gehre <M.Gehre@gmx.de> | 2015-10-16 18:46:30 +0000 |
commit | b785407c2835a7870f2909c218cc5d3589f5d778 (patch) | |
tree | 191f0f7cd9e055fb0c3c2ed5977caacd7ce161ab /clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp | |
parent | a6c9ee777ab53b14f7142f5886c0cbaa68e7e283 (diff) | |
download | bcm5719-llvm-b785407c2835a7870f2909c218cc5d3589f5d778.tar.gz bcm5719-llvm-b785407c2835a7870f2909c218cc5d3589f5d778.zip |
[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
Diffstat (limited to 'clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
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<ProTypeStaticCastDowncastCheck>( "cppcoreguidelines-pro-type-static-cast-downcast"); + CheckFactories.registerCheck<ProTypeUnionAccessCheck>( + "cppcoreguidelines-pro-type-union-access"); CheckFactories.registerCheck<misc::AssignOperatorSignatureCheck>( "cppcoreguidelines-c-copy-assignment-signature"); } |