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)
24 Finder->addMatcher(memberExpr(hasObjectExpression(hasType(recordDecl(isUnion())))).bind(
"expr"),
this);
27 void ProTypeUnionAccessCheck::check(
const MatchFinder::MatchResult &
Result) {
28 const auto *Matched = Result.Nodes.getNodeAs<MemberExpr>(
"expr");
29 diag(Matched->getMemberLoc(),
"do not access members of unions; use (boost::)variant instead");
std::unique_ptr< ast_matchers::MatchFinder > Finder