clang-tools  8.0.0
MultiwayPathsCoveredCheck.h
Go to the documentation of this file.
1 //===--- MultiwayPathsCoveredCheck.h - clang-tidy----------------*- C++ -*-===//
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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H
12 
13 #include "../ClangTidy.h"
14 #include "clang/ASTMatchers/ASTMatchFinder.h"
15 #include <iostream>
16 
17 namespace clang {
18 namespace tidy {
19 namespace hicpp {
20 
21 /// Find occasions where not all codepaths are explicitly covered in code.
22 /// This includes 'switch' without a 'default'-branch and 'if'-'else if'-chains
23 /// without a final 'else'-branch.
24 ///
25 /// For the user-facing documentation see:
26 /// http://clang.llvm.org/extra/clang-tidy/checks/hicpp-multiway-paths-covered.html
28 public:
30  : ClangTidyCheck(Name, Context),
31  WarnOnMissingElse(Options.get("WarnOnMissingElse", 0)) {}
32  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35 
36 private:
37  void handleSwitchWithDefault(const SwitchStmt *Switch, std::size_t CaseCount);
38  void handleSwitchWithoutDefault(
39  const SwitchStmt *Switch, std::size_t CaseCount,
40  const ast_matchers::MatchFinder::MatchResult &Result);
41  /// This option can be configured to warn on missing 'else' branches in an
42  /// 'if-else if' chain. The default is false because this option might be
43  /// noisy on some code bases.
44  const bool WarnOnMissingElse;
45 };
46 
47 } // namespace hicpp
48 } // namespace tidy
49 } // namespace clang
50 
51 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
MultiwayPathsCoveredCheck(StringRef Name, ClangTidyContext *Context)
Find occasions where not all codepaths are explicitly covered in code.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.