RedundantControlFlowCheck.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //===--- RedundantControlFlowCheck.h - clang-tidy----------------*- C++ -*-===//
  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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::readability {
  12. /// Eliminates redundant `return` statements at the end of a function that
  13. /// returns `void`.
  14. ///
  15. /// Eliminates redundant `continue` statements at the end of a loop body.
  16. ///
  17. /// For the user-facing documentation see:
  18. /// http://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-control-flow.html
  19. class RedundantControlFlowCheck : public ClangTidyCheck {
  20. public:
  21. RedundantControlFlowCheck(StringRef Name, ClangTidyContext *Context)
  22. : ClangTidyCheck(Name, Context) {}
  23. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  24. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  25. std::optional<TraversalKind> getCheckTraversalKind() const override {
  26. return TK_IgnoreUnlessSpelledInSource;
  27. }
  28. private:
  29. void
  30. checkRedundantReturn(const ast_matchers::MatchFinder::MatchResult &Result,
  31. const CompoundStmt *Block);
  32. void
  33. checkRedundantContinue(const ast_matchers::MatchFinder::MatchResult &Result,
  34. const CompoundStmt *Block);
  35. void issueDiagnostic(const ast_matchers::MatchFinder::MatchResult &Result,
  36. const CompoundStmt *Block, const SourceRange &StmtRange,
  37. const char *Diag);
  38. };
  39. } // namespace clang::tidy::readability
  40. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H