Malcolm Parsons | e7be4a0 | 2016-12-13 08:04:11 +0000 | [diff] [blame^] | 1 | //===--- RedundantFunctionPtrDereferenceCheck.cpp - clang-tidy-------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "RedundantFunctionPtrDereferenceCheck.h" |
| 11 | #include "clang/AST/ASTContext.h" |
| 12 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
| 13 | |
| 14 | using namespace clang::ast_matchers; |
| 15 | |
| 16 | namespace clang { |
| 17 | namespace tidy { |
| 18 | namespace readability { |
| 19 | |
| 20 | void RedundantFunctionPtrDereferenceCheck::registerMatchers(MatchFinder *Finder) { |
| 21 | Finder->addMatcher(unaryOperator(hasOperatorName("*"), |
| 22 | has(implicitCastExpr( |
| 23 | hasCastKind(CK_FunctionToPointerDecay)))) |
| 24 | .bind("op"), |
| 25 | this); |
| 26 | } |
| 27 | |
| 28 | void RedundantFunctionPtrDereferenceCheck::check(const MatchFinder::MatchResult &Result) { |
| 29 | const auto *Operator = Result.Nodes.getNodeAs<UnaryOperator>("op"); |
| 30 | diag(Operator->getOperatorLoc(), |
| 31 | "redundant repeated dereference of function pointer") |
| 32 | << FixItHint::CreateRemoval(Operator->getOperatorLoc()); |
| 33 | } |
| 34 | |
| 35 | } // namespace readability |
| 36 | } // namespace tidy |
| 37 | } // namespace clang |