Commit Graph

4 Commits

Author SHA1 Message Date
Stephen Kelly a5feefa3c7 [clang-tidy] Simplify redundant branch condition check
Differential Revision: https://reviews.llvm.org/D97151
2021-02-27 12:13:23 +00:00
Zinovy Nis 709112bce4 [clang-tidy] false-positive for bugprone-redundant-branch-condition in case of passed-by-ref params
Inspired by discussion in https://reviews.llvm.org/D91037

Differential Revision: https://reviews.llvm.org/D91495
2020-12-11 21:09:51 +03:00
Zinovy Nis 4364539b3a [clang-tidy] Fix crash in bugprone-redundant-branch-condition on ExprWithCleanups
Bug: https://bugs.llvm.org/show_bug.cgi?id=48008

Differential Revision: https://reviews.llvm.org/D91037
2020-11-14 08:35:21 +03:00
Adam Balogh 14dd073782 [Clang-Tidy] New check `bugprone-redundant-branch-condition`
Checking the same condition again in a nested `if` usually make no sense,
except if the value of the expression could have been changed between
the two checks. Although compilers may optimize this out, such code is
suspicious: the programmer may have meant to check something else.
Therefore it is worth to find such places in the code and notify the
user about the problem.

This patch implements a basic check for this problem. Currently it
only detects redundant conditions where the condition is a variable of
integral type. It also detects the possible bug if the variable is in an
//or// or //and// logical expression in the inner if and/or the variable
is in an //and// logical expression in the outer if statement. Negated
cases are not handled yet.

Differential Revision: https://reviews.llvm.org/D81272
2020-08-31 16:00:59 +02:00