[clang-tools-extra] 8c783b8 - [clang-tidy] Fix a false positive in readability-simplify-boolean-expr
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 24 10:29:32 PDT 2022
Author: Nathan James
Date: 2022-09-24T18:29:19+01:00
New Revision: 8c783b8ec78ec857e446a89a35463baed8026f40
URL: https://github.com/llvm/llvm-project/commit/8c783b8ec78ec857e446a89a35463baed8026f40
DIFF: https://github.com/llvm/llvm-project/commit/8c783b8ec78ec857e446a89a35463baed8026f40.diff
LOG: [clang-tidy] Fix a false positive in readability-simplify-boolean-expr
Reviewed By: LegalizeAdulthood
Differential Revision: https://reviews.llvm.org/D134590
Added:
Modified:
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-chained-conditional-return.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 8ae990a929dfd..afb4a1044a79a 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -472,8 +472,8 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
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);
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-chained-conditional-return.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-chained-conditional-return.cpp
index 7e97e9f717fbf..ff50528c215f4 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-chained-conditional-return.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-bool-expr-chained-conditional-return.cpp
@@ -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;
+}
More information about the cfe-commits
mailing list