10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
20 void NonCopyableObjectsCheck::registerMatchers(MatchFinder *Finder) {
36 auto BadFILEType = hasType(
37 namedDecl(hasAnyName(
"::FILE",
"FILE",
"std::FILE")).bind(
"type_decl"));
39 hasType(namedDecl(hasAnyName(
"::pthread_cond_t",
"::pthread_mutex_t",
40 "pthread_cond_t",
"pthread_mutex_t"))
42 auto BadEitherType = anyOf(BadFILEType, BadPOSIXType);
45 namedDecl(anyOf(varDecl(BadFILEType), fieldDecl(BadFILEType)))
48 Finder->addMatcher(parmVarDecl(BadPOSIXType).bind(
"decl"),
this);
50 expr(unaryOperator(hasOperatorName(
"*"), BadEitherType)).bind(
"expr"),
55 const auto *
D = Result.Nodes.getNodeAs<NamedDecl>(
"decl");
56 const auto *BD = Result.Nodes.getNodeAs<NamedDecl>(
"type_decl");
57 const auto *
E = Result.Nodes.getNodeAs<Expr>(
"expr");
60 diag(
D->getLocation(),
"%0 declared as type '%1', which is unsafe to copy"
61 "; did you mean '%1 *'?")
62 <<
D << BD->getName();
65 "expression has opaque data structure type %0; type should only be "
66 "used as a pointer and not dereferenced")