11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/ASTMatchers/ASTMatchers.h" 22 void OverloadedUnaryAndCheck::registerMatchers(
23 ast_matchers::MatchFinder *Finder) {
26 if (!getLangOpts().CPlusPlus)
31 cxxMethodDecl(parameterCountIs(0), hasOverloadedOperatorName(
"&"))
38 unless(cxxMethodDecl()),
39 functionDecl(parameterCountIs(1), hasOverloadedOperatorName(
"&"))
44 void OverloadedUnaryAndCheck::check(
const MatchFinder::MatchResult &Result) {
45 const auto *Decl = Result.Nodes.getNodeAs<FunctionDecl>(
"overload");
46 diag(Decl->getLocStart(),
47 "do not overload unary operator&, it is dangerous.");