11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 21 void NonCopyableObjectsCheck::registerMatchers(MatchFinder *Finder) {
37 auto BadFILEType = hasType(
38 namedDecl(hasAnyName(
"::FILE",
"FILE",
"std::FILE")).bind(
"type_decl"));
40 hasType(namedDecl(hasAnyName(
"::pthread_cond_t",
"::pthread_mutex_t",
41 "pthread_cond_t",
"pthread_mutex_t"))
43 auto BadEitherType = anyOf(BadFILEType, BadPOSIXType);
46 namedDecl(anyOf(varDecl(BadFILEType), fieldDecl(BadFILEType)))
49 Finder->addMatcher(parmVarDecl(BadPOSIXType).bind(
"decl"),
this);
51 expr(unaryOperator(hasOperatorName(
"*"), BadEitherType)).bind(
"expr"),
55 void NonCopyableObjectsCheck::check(
const MatchFinder::MatchResult &
Result) {
56 const auto *
D = Result.Nodes.getNodeAs<NamedDecl>(
"decl");
57 const auto *BD = Result.Nodes.getNodeAs<NamedDecl>(
"type_decl");
58 const auto *E = Result.Nodes.getNodeAs<Expr>(
"expr");
61 diag(
D->getLocation(),
"%0 declared as type '%1', which is unsafe to copy" 62 "; did you mean '%1 *'?")
63 <<
D << BD->getName();
66 "expression has opaque data structure type %0; type should only be " 67 "used as a pointer and not dereferenced")
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//