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
27 class MultiwayPathsCoveredCheck : public ClangTidyCheck {
28 public:
29 MultiwayPathsCoveredCheck(StringRef Name, ClangTidyContext *Context)
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
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::hicpp::MultiwayPathsCoveredCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: MultiwayPathsCoveredCheck.cpp:21
clang::tidy::hicpp::MultiwayPathsCoveredCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: MultiwayPathsCoveredCheck.cpp:93
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidy.h:183
clang::tidy::hicpp::MultiwayPathsCoveredCheck::MultiwayPathsCoveredCheck
MultiwayPathsCoveredCheck(StringRef Name, ClangTidyContext *Context)
Definition: MultiwayPathsCoveredCheck.h:29
clang::tidy::hicpp::MultiwayPathsCoveredCheck
Find occasions where not all codepaths are explicitly covered in code.
Definition: MultiwayPathsCoveredCheck.h:27
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:98
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition: ClangdServer.cpp:60
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:100
clang::tidy::hicpp::MultiwayPathsCoveredCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: MultiwayPathsCoveredCheck.cpp:26