10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
34 auto BadFILEType = hasType(
35 namedDecl(hasAnyName(
"::FILE",
"FILE",
"std::FILE")).bind(
"type_decl"));
37 hasType(namedDecl(hasAnyName(
"::pthread_cond_t",
"::pthread_mutex_t",
38 "pthread_cond_t",
"pthread_mutex_t"))
40 auto BadEitherType = anyOf(BadFILEType, BadPOSIXType);
43 namedDecl(anyOf(varDecl(BadFILEType), fieldDecl(BadFILEType)))
46 Finder->addMatcher(parmVarDecl(BadPOSIXType).bind(
"decl"),
this);
48 expr(unaryOperator(hasOperatorName(
"*"), BadEitherType)).bind(
"expr"),
53 const auto *D = Result.Nodes.getNodeAs<NamedDecl>(
"decl");
54 const auto *BD = Result.Nodes.getNodeAs<NamedDecl>(
"type_decl");
55 const auto *
E = Result.Nodes.getNodeAs<Expr>(
"expr");
58 diag(D->getLocation(),
"%0 declared as type '%1', which is unsafe to copy"
59 "; did you mean '%1 *'?")
60 << D << BD->getName();
63 "expression has opaque data structure type %0; type should only be "
64 "used as a pointer and not dereferenced")
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.