[clang-tools-extra] [clang-tidy] Fix false negative for binary logical expressions for tw… (PR #230846)
Abhay Singh via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 12 00:06:51 PDT 2026
https://github.com/Abhay13332 updated https://github.com/llvm/llvm-project/pull/230846
>From 8854364e5e9a1c2e2620ea4fe33fca7d8d519b79 Mon Sep 17 00:00:00 2001
From: abhay13332 <abhaysingh13072009 at gmail.com>
Date: Sun, 11 Oct 2026 01:09:35 +0530
Subject: [PATCH 1/7] [clang-tidy] Fix false negative for binary logical
expressions for two operands in bugprone-redundant-branch-condition
---
.../bugprone/RedundantBranchConditionCheck.cpp | 7 +++----
clang-tools-extra/docs/ReleaseNotes.md | 6 ++++++
.../bugprone/redundant-branch-condition.cpp | 15 ++++++++++++++-
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
index 8d608dd4b0e66..f6c6373969b34 100644
--- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -76,10 +76,9 @@ void RedundantBranchConditionCheck::registerMatchers(MatchFinder *Finder) {
ifStmt(
hasCondition(anyOf(
declRefExpr(hasDeclaration(ImmutableVar)).bind(OuterIfVar1Str),
- binaryOperator(
- hasOperatorName("&&"),
- hasEitherOperand(declRefExpr(hasDeclaration(ImmutableVar))
- .bind(OuterIfVar2Str))))),
+ binaryOperator(hasOperatorName("&&"),
+ forEach((declRefExpr(hasDeclaration(ImmutableVar))
+ .bind(OuterIfVar2Str)))))),
hasThen(hasDescendant(
ifStmt(hasCondition(anyOf(
declRefExpr(hasDeclaration(
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 42451c4590592..8a6cb3964c4fd 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -198,6 +198,11 @@ infrastructure are described first, followed by tool-specific sections.
<clang-tidy/checks/bugprone/std-namespace-modification>` when checking
lambda closure types used as template arguments.
+- Improved {doc}`bugprone-redundant-branch-condition
+ <clang-tidy/checks/bugprone/redundant-branch-condition>` check fix for
+ false negative when there are two declaration statement in if with &&
+ it skips the second one bind with first one only preveiously.
+
- Improved {doc}`cppcoreguidelines-missing-std-forward
<clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check by diagnosing
unforwarded `auto&&` parameters in C++20 abbreviated function templates.
@@ -352,6 +357,7 @@ infrastructure are described first, followed by tool-specific sections.
<clang-tidy/checks/readability/use-std-min-max>` check by fixing spurious
trailing semicolons and lost comments when the `if` body has no braces.
+
#### Removed checks
- Removed the deprecated `zircon-temporary-objects` check. Users should migrate to
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/redundant-branch-condition.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/redundant-branch-condition.cpp
index ad2238ff9984f..57ab6456a9987 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/redundant-branch-condition.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/redundant-branch-condition.cpp
@@ -12,7 +12,7 @@ bool tryToExtinguishByVal(bool);
void tryPutFireOut();
bool callTheFD();
void scream();
-
+bool isFireFighterComing();
bool someOtherCondition();
//===--- Basic Positives --------------------------------------------------===//
@@ -278,6 +278,19 @@ void positive_direct_outer_and_rhs() {
// CHECK-FIXES: {{^\ *$}}
}
}
+void positive_direct_outer_and_rhs_bool() {
+ bool onFire = isBurning();
+ bool isComing = isFireFighterComing();
+ if (isComing && onFire) {
+ if (onFire) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'onFire' [bugprone-redundant-branch-condition]
+ // CHECK-FIXES: {{^\ *$}}
+ scream();
+ }
+ // CHECK-FIXES: {{^\ *$}}
+ }
+}
+
void positive_indirect_outer_and_rhs() {
bool onFire = isBurning();
>From e8b26feed4bce00e77e3e6722d2bebee65a480b6 Mon Sep 17 00:00:00 2001
From: abhay13332 <abhaysingh13072009 at gmail.com>
Date: Sun, 11 Oct 2026 11:21:51 +0530
Subject: [PATCH 2/7] [clang-tidy] Fix spacing issues in Release Notes
---
clang-tools-extra/docs/ReleaseNotes.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 950d11d8bfe6e..fd6683547bd06 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -215,6 +215,7 @@ infrastructure are described first, followed by tool-specific sections.
<clang-tidy/checks/bugprone/redundant-branch-condition>` check fix for
false negative when there are two declaration statement in if with &&
it skips the second one bind with first one only preveiously.
+
- Improved {doc}`bugprone-unchecked-optional-access
<clang-tidy/checks/bugprone/unchecked-optional-access>` by fixing false
positives on `bsl::optional` and `bdlb::NullableValue` constructed from a
>From fd3ffd80e3824a2e3510481ce0c2ec140d5047f0 Mon Sep 17 00:00:00 2001
From: Abhay Singh <135463427+Abhay13332 at users.noreply.github.com>
Date: Sun, 11 Oct 2026 20:42:17 +0530
Subject: [PATCH 3/7] Update clang-tools-extra/docs/ReleaseNotes.md
Co-authored-by: Zeyi Xu <zeyi2 at nekoarch.cc>
---
clang-tools-extra/docs/ReleaseNotes.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index fd6683547bd06..9121d2e0b655c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -414,7 +414,6 @@ infrastructure are described first, followed by tool-specific sections.
<clang-tidy/checks/readability/use-std-min-max>` check by fixing spurious
trailing semicolons and lost comments when the `if` body has no braces.
-
#### Removed checks
- Removed the deprecated `zircon-temporary-objects` check. Users should migrate to
>From 935eb078ec2be92b314b02f914e332a5eaf322a4 Mon Sep 17 00:00:00 2001
From: Abhay Singh <135463427+Abhay13332 at users.noreply.github.com>
Date: Sun, 11 Oct 2026 23:39:25 +0530
Subject: [PATCH 4/7] Update clang-tools-extra/docs/ReleaseNotes.md
Co-authored-by: EugeneZelenko <eugene.zelenko at gmail.com>
---
clang-tools-extra/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 9121d2e0b655c..726370f6c42a8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -213,7 +213,7 @@ infrastructure are described first, followed by tool-specific sections.
- Improved {doc}`bugprone-redundant-branch-condition
<clang-tidy/checks/bugprone/redundant-branch-condition>` check fix for
- false negative when there are two declaration statement in if with &&
+ false negative when there are two declaration statement in `if` with `&&`
it skips the second one bind with first one only preveiously.
- Improved {doc}`bugprone-unchecked-optional-access
>From dc035a63c1af461dafd4365ccb50bc4e6b70ca81 Mon Sep 17 00:00:00 2001
From: abhay13332 <abhaysingh13072009 at gmail.com>
Date: Sun, 11 Oct 2026 23:44:59 +0530
Subject: [PATCH 5/7] [clang-Tidy] Merge bugprone-redundant-branch-condition
fixes in one
---
clang-tools-extra/docs/ReleaseNotes.md | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 726370f6c42a8..38f0ff19ab7dd 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -203,18 +203,17 @@ infrastructure are described first, followed by tool-specific sections.
the pointer points to an incomplete (forward-declared) type.
- Improved {doc}`bugprone-redundant-branch-condition
- <clang-tidy/checks/bugprone/redundant-branch-condition>` check by fixing
- false positives when the condition variable is changed later in a loop that
- encloses the inner `if`.
+ <clang-tidy/checks/bugprone/redundant-branch-condition>` check:
+
+ - Fixed false positives when the condition variable is changed later in a loop that
+ encloses the inner `if`.
+
+ - Fixed for false negative when there are two declaration statement in `if` with `&&`
+ it skips the second one bind with first one only preveiously.
- Fixed a crash in {doc}`bugprone-std-namespace-modification
<clang-tidy/checks/bugprone/std-namespace-modification>` when checking
lambda closure types used as template arguments.
-
-- Improved {doc}`bugprone-redundant-branch-condition
- <clang-tidy/checks/bugprone/redundant-branch-condition>` check fix for
- false negative when there are two declaration statement in `if` with `&&`
- it skips the second one bind with first one only preveiously.
- Improved {doc}`bugprone-unchecked-optional-access
<clang-tidy/checks/bugprone/unchecked-optional-access>` by fixing false
>From 25be8bef831e79ce384b00f5ea9e52211ac274ca Mon Sep 17 00:00:00 2001
From: Abhay Singh <135463427+Abhay13332 at users.noreply.github.com>
Date: Mon, 12 Oct 2026 07:51:48 +0530
Subject: [PATCH 6/7] Update clang-tools-extra/docs/ReleaseNotes.md with
negatives as negative
Co-authored-by: EugeneZelenko <eugene.zelenko at gmail.com>
---
clang-tools-extra/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index 38f0ff19ab7dd..cba1ebe8158bb 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -208,7 +208,7 @@ infrastructure are described first, followed by tool-specific sections.
- Fixed false positives when the condition variable is changed later in a loop that
encloses the inner `if`.
- - Fixed for false negative when there are two declaration statement in `if` with `&&`
+ - Fixed false negatives when there are two declaration statement in `if` with `&&`
it skips the second one bind with first one only preveiously.
- Fixed a crash in {doc}`bugprone-std-namespace-modification
>From 1017d34d36db457b7b0cc1a886482df4b6cd1404 Mon Sep 17 00:00:00 2001
From: Abhay Singh <135463427+Abhay13332 at users.noreply.github.com>
Date: Mon, 12 Oct 2026 07:52:07 +0530
Subject: [PATCH 7/7] Update clang-tools-extra/docs/ReleaseNotes.md
Co-authored-by: EugeneZelenko <eugene.zelenko at gmail.com>
---
clang-tools-extra/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md
index cba1ebe8158bb..c8e1be77cf6cb 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -209,7 +209,7 @@ infrastructure are described first, followed by tool-specific sections.
encloses the inner `if`.
- Fixed false negatives when there are two declaration statement in `if` with `&&`
- it skips the second one bind with first one only preveiously.
+ it skips the second one bind with first one only previously.
- Fixed a crash in {doc}`bugprone-std-namespace-modification
<clang-tidy/checks/bugprone/std-namespace-modification>` when checking
More information about the cfe-commits
mailing list