blob: fa503c57802fb5f127826b5ba659f71cc30a4a72 [file] [log] [blame]
Malcolm Parsonse7be4a02016-12-13 08:04:11 +00001//===--- 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
14using namespace clang::ast_matchers;
15
16namespace clang {
17namespace tidy {
18namespace readability {
19
20void RedundantFunctionPtrDereferenceCheck::registerMatchers(MatchFinder *Finder) {
21 Finder->addMatcher(unaryOperator(hasOperatorName("*"),
22 has(implicitCastExpr(
23 hasCastKind(CK_FunctionToPointerDecay))))
24 .bind("op"),
25 this);
26}
27
28void 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