clang-tools 6.0.0

ProTypeUnionAccessCheck.cpp
Go to the documentation of this file.
1 //===--- ProTypeUnionAccessCheck.cpp - clang-tidy--------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "ProTypeUnionAccessCheck.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13
14 using namespace clang::ast_matchers;
15
16 namespace clang {
17 namespace tidy {
18 namespace cppcoreguidelines {
19
20 void ProTypeUnionAccessCheck::registerMatchers(MatchFinder *Finder) {
21 if (!getLangOpts().CPlusPlus)
22 return;
23
24 Finder->addMatcher(
25 memberExpr(hasObjectExpression(hasType(recordDecl(isUnion()))))
26 .bind("expr"),
27 this);
28 }
29
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");
34 }
35
36 } // namespace cppcoreguidelines
37 } // namespace tidy
38 } // namespace clang
clang::ast_matchers
Definition: ClangTidyDiagnosticConsumer.h:27
ProTypeUnionAccessCheck.h
clang
Definition: AndroidTidyModule.cpp:28