clang-tools
23.0.0git
llvm-project
clang-tools-extra
clang-tidy
bugprone
UnhandledCodePathsCheck.h
Go to the documentation of this file.
1
//===----------------------------------------------------------------------===//
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
9
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNHANDLEDCODEPATHSCHECK_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNHANDLEDCODEPATHSCHECK_H
11
12
#include "
../ClangTidyCheck.h
"
13
14
namespace
clang::tidy::bugprone
{
15
16
/// Find occasions where not all codepaths are explicitly covered in code.
17
/// This includes 'switch' without a 'default'-branch and 'if'-'else if'-chains
18
/// without a final 'else'-branch.
19
///
20
/// For the user-facing documentation see:
21
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/unhandled-code-paths.html
22
class
UnhandledCodePathsCheck
:
public
ClangTidyCheck
{
23
public
:
24
UnhandledCodePathsCheck
(StringRef Name,
ClangTidyContext
*Context)
25
:
ClangTidyCheck
(Name, Context),
26
WarnOnMissingElse(Options.get(
"WarnOnMissingElse"
, false)) {}
27
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
28
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
29
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
30
31
private
:
32
void
handleSwitchWithoutDefault(
33
const
SwitchStmt *Switch, std::size_t CaseCount,
34
const
ast_matchers::MatchFinder::MatchResult &Result);
35
/// This option can be configured to warn on missing 'else' branches in an
36
/// 'if-else if' chain. The default is false because this option might be
37
/// noisy on some code bases.
38
const
bool
WarnOnMissingElse;
39
};
40
41
}
// namespace clang::tidy::bugprone
42
43
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNHANDLEDCODEPATHSCHECK_H
ClangTidyCheck.h
ClangTidyCheck
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition
ClangTidyDiagnosticConsumer.h:70
clang::tidy::bugprone::UnhandledCodePathsCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
UnhandledCodePathsCheck.cpp:89
clang::tidy::bugprone::UnhandledCodePathsCheck::UnhandledCodePathsCheck
UnhandledCodePathsCheck(StringRef Name, ClangTidyContext *Context)
Definition
UnhandledCodePathsCheck.h:24
clang::tidy::bugprone::UnhandledCodePathsCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Definition
UnhandledCodePathsCheck.cpp:18
clang::tidy::bugprone::UnhandledCodePathsCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
UnhandledCodePathsCheck.cpp:22
clang::tidy::bugprone
Definition
ArgumentCommentCheck.cpp:19
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition
ClangTidyOptions.h:128
Generated on
for clang-tools by
1.14.0