[clang-tidy] Fix a false positive in readability-simplify-boolean-expr
authorNathan James <n.james93@hotmail.co.uk>
Sat, 24 Sep 2022 17:29:17 +0000 (18:29 +0100)
committerTobias Hieta <tobias@hieta.se>
Tue, 18 Oct 2022 06:28:42 +0000 (08:28 +0200)
Reviewed By: LegalizeAdulthood

Differential Revision: https://reviews.llvm.org/D134590

(cherry picked from commit 8c783b8ec78ec857e446a89a35463baed8026f40)

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

index 8ae990a..afb4a10 100644 (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);
index 7e97e9f..ff50528 100644 (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;
+}