Skip to content

Commit dfef316

Browse files
njames93tru
authored andcommitted
[clang-tidy] Fix a false positive in readability-simplify-boolean-expr
Reviewed By: LegalizeAdulthood Differential Revision: https://reviews.llvm.org/D134590 (cherry picked from commit 8c783b8)
1 parent d35bc70 commit dfef316

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
472472
checkSingleStatement(If->getThen(), parseReturnLiteralBool);
473473
if (ThenReturnBool &&
474474
ThenReturnBool.Bool != TrailingReturnBool.Bool) {
475-
if (Check->ChainedConditionalReturn ||
476-
(!PrevIf && If->getElse() == nullptr)) {
475+
if ((Check->ChainedConditionalReturn || !PrevIf) &&
476+
If->getElse() == nullptr) {
477477
Check->replaceCompoundReturnWithCondition(
478478
Context, cast<ReturnStmt>(*Second), TrailingReturnBool.Bool,
479479
If, ThenReturnBool.Item);

clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-chained-conditional-return.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ bool complex_chained_if_return_return_negated(int i) {
9292
// CHECK-FIXES: {{^}} }{{$}}
9393
// CHECK-FIXES: {{^ return i <= 10;$}}
9494
// CHECK-FIXES: {{^}$}}
95+
96+
97+
bool PR57819(int x) {
98+
// False positive introduced in clang-tidy-15
99+
// Expect no warning here.
100+
if (x > 0)
101+
return false;
102+
else {
103+
}
104+
return true;
105+
}

0 commit comments

Comments
 (0)