[PATCH] D13784: [clang-tidy] add check cppcoreguidelines-pro-type-union-access
Matthias Gehre via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 15 13:49:34 PDT 2015
mgehre created this revision.
mgehre added reviewers: alexfh, sbenza, bkramer, aaron.ballman.
mgehre added a subscriber: cfe-commits.
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
http://reviews.llvm.org/D13784
Files:
clang-tidy/cppcoreguidelines/CMakeLists.txt
clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.cpp
clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.h
docs/clang-tidy/checks/cppcoreguidelines-pro-type-union-access.rst
docs/clang-tidy/checks/list.rst
test/clang-tidy/cppcoreguidelines-pro-type-union-access.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13784.37515.patch
Type: text/x-patch
Size: 6877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151015/3dec8cf2/attachment.bin>
More information about the cfe-commits
mailing list