10#include "clang/AST/Expr.h"
11#include "clang/AST/Type.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "clang/ASTMatchers/ASTMatchers.h"
23 qualType(unless(hasCanonicalType(pointsTo(voidType()))))
24 .bind(
"target_type")),
28 expr(hasType(qualType(unless(pointsTo(voidType())))
29 .bind(
"source_type")))),
31 qualType(pointsTo(voidType())).bind(
"void_type")))
37 const auto TT = *Result.Nodes.getNodeAs<QualType>(
"target_type");
38 const auto ST = *Result.Nodes.getNodeAs<QualType>(
"source_type");
39 const auto VT = *Result.Nodes.getNodeAs<QualType>(
"void_type");
40 const auto *
CE = Result.Nodes.getNodeAs<ExplicitCastExpr>(
"cast");
41 diag(
CE->getExprLoc(),
"do not cast %0 to %1 through %2") << ST << TT << VT;
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.