[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 8c783b8ec78ec857e446a89a35463baed8026f40)
This commit is contained in:
Nathan James 2022-09-24 18:29:17 +01:00 committed by Tobias Hieta
parent d35bc70e82
commit dfef316bb3
2 changed files with 13 additions and 2 deletions

View file

@ -472,8 +472,8 @@ public:
checkSingleStatement(If->getThen(), parseReturnLiteralBool);
if (ThenReturnBool &&
ThenReturnBool.Bool != TrailingReturnBool.Bool) {
if (Check->ChainedConditionalReturn ||
(!PrevIf && If->getElse() == nullptr)) {
if ((Check->ChainedConditionalReturn || !PrevIf) &&
If->getElse() == nullptr) {
Check->replaceCompoundReturnWithCondition(
Context, cast<ReturnStmt>(*Second), TrailingReturnBool.Bool,
If, ThenReturnBool.Item);

View file

@ -92,3 +92,14 @@ bool complex_chained_if_return_return_negated(int i) {
// CHECK-FIXES: {{^}} }{{$}}
// CHECK-FIXES: {{^ return i <= 10;$}}
// CHECK-FIXES: {{^}$}}
bool PR57819(int x) {
// False positive introduced in clang-tidy-15
// Expect no warning here.
if (x > 0)
return false;
else {
}
return true;
}