RedundantFunctionPtrDereferenceCheck.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. //===--- RedundantFunctionPtrDereferenceCheck.cpp - clang-tidy-------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "RedundantFunctionPtrDereferenceCheck.h"
  9. #include "clang/AST/ASTContext.h"
  10. #include "clang/ASTMatchers/ASTMatchFinder.h"
  11. using namespace clang::ast_matchers;
  12. namespace clang::tidy::readability {
  13. void RedundantFunctionPtrDereferenceCheck::registerMatchers(MatchFinder *Finder) {
  14. Finder->addMatcher(
  15. traverse(TK_AsIs, unaryOperator(hasOperatorName("*"),
  16. has(implicitCastExpr(hasCastKind(
  17. CK_FunctionToPointerDecay))))
  18. .bind("op")),
  19. this);
  20. }
  21. void RedundantFunctionPtrDereferenceCheck::check(const MatchFinder::MatchResult &Result) {
  22. const auto *Operator = Result.Nodes.getNodeAs<UnaryOperator>("op");
  23. diag(Operator->getOperatorLoc(),
  24. "redundant repeated dereference of function pointer")
  25. << FixItHint::CreateRemoval(Operator->getOperatorLoc());
  26. }
  27. } // namespace clang::tidy::readability