11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
15 using namespace clang::ast_matchers;
25 bool isPOSIXTypeName(StringRef ClassName) {
26 static const char *
const TypeNames[] = {
32 return std::binary_search(std::begin(TypeNames), std::end(TypeNames),
36 bool isFILETypeName(StringRef ClassName) {
37 static const char *
const TypeNames[] = {
42 return std::binary_search(std::begin(TypeNames), std::end(TypeNames),
47 return isFILETypeName(Node.getQualifiedNameAsString());
51 return isPOSIXTypeName(Node.getQualifiedNameAsString());
55 void NonCopyableObjectsCheck::registerMatchers(MatchFinder *
Finder) {
66 auto BadFILEType = hasType(namedDecl(isFILEType()).bind(
"type_decl"));
67 auto BadPOSIXType = hasType(namedDecl(isPOSIXType()).bind(
"type_decl"));
68 auto BadEitherType = anyOf(BadFILEType, BadPOSIXType);
71 namedDecl(anyOf(varDecl(BadFILEType), fieldDecl(BadFILEType)))
74 Finder->addMatcher(parmVarDecl(BadPOSIXType).bind(
"decl"),
this);
76 expr(unaryOperator(hasOperatorName(
"*"), BadEitherType)).bind(
"expr"),
80 void NonCopyableObjectsCheck::check(
const MatchFinder::MatchResult &
Result) {
81 const auto *D = Result.Nodes.getNodeAs<NamedDecl>(
"decl");
82 const auto *BD = Result.Nodes.getNodeAs<NamedDecl>(
"type_decl");
83 const auto *E = Result.Nodes.getNodeAs<Expr>(
"expr");
86 diag(D->getLocation(),
"%0 declared as type '%1', which is unsafe to copy"
87 "; did you mean '%1 *'?")
88 << D << BD->getName();
91 "expression has opaque data structure type %0; type should only be "
92 "used as a pointer and not dereferenced")
AST_MATCHER(Type, isStrictlyInteger)
std::unique_ptr< ast_matchers::MatchFinder > Finder