diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2016-02-01 15:31:15 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2016-02-01 15:31:15 +0000 |
commit | c3975b7d6af5970598db272f9b13423d2e09d5ab (patch) | |
tree | 62f4218c507699e26ed1270536422870938496fa /clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h | |
parent | a052037034df09335b964ef9dae91bb9b54c94fa (diff) | |
download | bcm5719-llvm-c3975b7d6af5970598db272f9b13423d2e09d5ab.tar.gz bcm5719-llvm-c3975b7d6af5970598db272f9b13423d2e09d5ab.zip |
Add a new check, readability-redundant-control-flow, that check for some forms of redundant control flow statements. Currently checks for return statements at the end of a function with a void return type and continue statements at the end of looping statements.
Patch by Richard Thomson.
llvm-svn: 259362
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h new file mode 100644 index 00000000000..4b8b6fbf20e --- /dev/null +++ b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h @@ -0,0 +1,51 @@ +//===--- RedundantControlFlowCheck.h - clang-tidy----------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H + +#include "../ClangTidy.h" + +namespace clang { +namespace tidy { +namespace readability { + +/// Eliminates redundant `return` statements at the end of a function that +/// returns `void`. +/// +/// Eliminates redundant `continue` statements at the end of a loop body. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/readability-redundant-control-flow.html +class RedundantControlFlowCheck : public ClangTidyCheck { +public: + RedundantControlFlowCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) {} + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + +private: + void + checkRedundantReturn(const ast_matchers::MatchFinder::MatchResult &Result, + const CompoundStmt *Block); + + void + checkRedundantContinue(const ast_matchers::MatchFinder::MatchResult &Result, + const CompoundStmt *Block); + + void issueDiagnostic(const ast_matchers::MatchFinder::MatchResult &Result, + const CompoundStmt *Block, const SourceRange &StmtRange, + const char *Diag); +}; + +} // namespace readability +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H |