11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 using namespace clang::ast_matchers;
18 namespace cppcoreguidelines {
20 void ProTypeUnionAccessCheck::registerMatchers(MatchFinder *
Finder) {
21 if (!getLangOpts().CPlusPlus)
25 memberExpr(hasObjectExpression(hasType(recordDecl(isUnion()))))
30 void ProTypeUnionAccessCheck::check(
const MatchFinder::MatchResult &Result) {
31 const auto *Matched = Result.Nodes.getNodeAs<MemberExpr>(
"expr");
32 diag(Matched->getMemberLoc(),
33 "do not access members of unions; use (boost::)variant instead");
std::unique_ptr< ast_matchers::MatchFinder > Finder