[PATCH] D91495: [clang-tidy] false-positive for bugprone-redundant-branch-condition in case of passed-by-ref params
Zinovy Nis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 15 07:19:05 PST 2020
zinovy.nis created this revision.
zinovy.nis added reviewers: aaron.ballman, baloghadamsoftware.
Herald added subscribers: cfe-commits, rnkovacs, xazax.hun.
Herald added a project: clang.
zinovy.nis requested review of this revision.
Inspired by discussion in https://reviews.llvm.org/D91037
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91495
Files:
clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -6,7 +6,8 @@
bool isBurning();
bool isReallyBurning();
bool isCollapsing();
-void tryToExtinguish(bool&);
+bool tryToExtinguish(bool&);
+bool tryToExtinguishByVal(bool &);
void tryPutFireOut();
bool callTheFD();
void scream();
@@ -948,6 +949,24 @@
}
}
+void negative_by_ref(bool isSet) {
+ if (tryToExtinguish(isSet) && isSet) {
+ if (tryToExtinguish(isSet) && isSet) {
+ // NO-MESSAGE: fire may have been extinguished
+ scream();
+ }
+ }
+}
+
+void negative_by_val(bool isSet) {
+ if (tryToExtinguishByVal(isSet) && isSet) {
+ if (tryToExtinguishByVal(isSet) && isSet) {
+ // NO-MESSAGE: fire may have been extinguished
+ scream();
+ }
+ }
+}
+
void negative_reassigned() {
bool onFire = isBurning();
if (onFire) {
@@ -1077,9 +1096,9 @@
int positive_expr_with_cleanups() {
class RetT {
public:
- RetT(const int _code) : code_(_code) {}
- bool Ok() const { return code_ == 0; }
- static RetT Test(bool &_isSet) { return 0; }
+ RetT(const int code);
+ bool Ok() const;
+ static RetT Test(bool isSet);
private:
int code_;
Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -75,6 +75,9 @@
if (hasPtrOrReferenceInFunc(Func, CondVar))
return;
+ if (isChangedBefore(OuterIf->getCond(), InnerIf, CondVar, Result.Context))
+ return;
+
if (isChangedBefore(OuterIf->getThen(), InnerIf, CondVar, Result.Context))
return;
@@ -123,7 +126,7 @@
CharSourceRange::getTokenRange(IfBegin, IfEnd));
}
- // For comound statements also remove the right brace at the end.
+ // For compound statements also remove the right brace at the end.
if (isa<CompoundStmt>(Body))
Diag << FixItHint::CreateRemoval(
CharSourceRange::getTokenRange(Body->getEndLoc(), Body->getEndLoc()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91495.305360.patch
Type: text/x-patch
Size: 2399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201115/85254eda/attachment.bin>
More information about the cfe-commits
mailing list