Skip to content

Commit eb069ae

Browse files
committed
add MatchIf
1 parent 39881dc commit eb069ae

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,21 @@ void ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
7171
}
7272

7373
void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
74-
ast_matchers::internal::Matcher<FunctionDecl> Nothing = unless(anything());
74+
auto MatchIf = [](bool Enabled, const auto &Matcher) {
75+
ast_matchers::internal::Matcher<FunctionDecl> Nothing = unless(anything());
76+
return Enabled ? Matcher : Nothing;
77+
};
7578
Finder->addMatcher(
7679
functionDecl(
7780
isDefinition(),
7881
anyOf(
79-
CheckNothrowFunctions ? isNoThrow() : Nothing,
80-
allOf(anyOf(CheckDestructors ? cxxDestructorDecl() : Nothing,
81-
CheckMoveMemberFunctions
82-
? anyOf(cxxConstructorDecl(isMoveConstructor()),
83-
cxxMethodDecl(isMoveAssignmentOperator()))
84-
: Nothing,
85-
CheckMain ? isMain() : Nothing,
82+
MatchIf(CheckNothrowFunctions, isNoThrow()),
83+
allOf(anyOf(MatchIf(CheckDestructors, cxxDestructorDecl()),
84+
MatchIf(
85+
CheckMoveMemberFunctions,
86+
anyOf(cxxConstructorDecl(isMoveConstructor()),
87+
cxxMethodDecl(isMoveAssignmentOperator()))),
88+
MatchIf(CheckMain, isMain()),
8689
allOf(isEnabled(CheckedSwapFunctions),
8790
hasAtLeastOneParameter())),
8891
unless(isExplicitThrow())),

0 commit comments

Comments
 (0)