diff options
author | Etienne Bergeron <etienneb@google.com> | 2016-04-26 17:30:30 +0000 |
---|---|---|
committer | Etienne Bergeron <etienneb@google.com> | 2016-04-26 17:30:30 +0000 |
commit | bda187decd34572c8bf601f9ca4928cb0e880606 (patch) | |
tree | b99d311103cf4f16036c3d2aafd0f78949587e17 /clang-tools-extra/docs/clang-tidy | |
parent | 71515e57f9597cd79a920b01c1646b704557d2b6 (diff) | |
download | bcm5719-llvm-bda187decd34572c8bf601f9ca4928cb0e880606.tar.gz bcm5719-llvm-bda187decd34572c8bf601f9ca4928cb0e880606.zip |
[clang-tidy] New checker for redundant expressions.
Summary:
This checker finds redundant expression on both side of a binary operator.
The current implementation provide a function to check whether expressions
are equivalent. This implementation is able to recognize the common
subset encounter in C++ program. Side-effects like "x++" are not considered
to be equivalent.
There are many False Positives related to macros and to floating point
computations (detecting NaN). The checker is ignoring these cases.
Example:
```
if( !dst || dst->depth != desired_depth ||
dst->nChannels != desired_num_channels ||
dst_size.width != src_size.width ||
dst_size.height != dst_size.height ) <<--- bug
{
```
Reviewers: alexfh
Subscribers: danielmarjamaki, fahlgren, jordan_rose, zaks.anna, Eugene.Zelenko, cfe-commits
Differential Revision: http://reviews.llvm.org/D19451
llvm-svn: 267574
Diffstat (limited to 'clang-tools-extra/docs/clang-tidy')
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/list.rst | 1 | ||||
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/misc-redundant-expression.rst | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index db31a73fbba..113b341add2 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -67,6 +67,7 @@ Clang-Tidy Checks misc-noexcept-move-constructor misc-non-copyable-objects misc-pointer-and-integral-operation + misc-redundant-expression misc-sizeof-container misc-sizeof-expression misc-static-assert diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-redundant-expression.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-redundant-expression.rst new file mode 100644 index 00000000000..812031d91b2 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/misc-redundant-expression.rst @@ -0,0 +1,20 @@ +.. title:: clang-tidy - misc-redundant-expression + +misc-redundant-expression +========================= + +Detect redundant expressions which are typically errors due to copy-paste. + +Depending on the operator expressions may be + * redundant, + * always be `true`, + * always be `false`, + * always be a constant (zero or one) + +Example: +.. code:: c++ + + ((x+1) | (x+1)) // (x+1) is redundant + (p->x == p->x) // always true + (p->x < p->x) // always false + (speed - speed + 1 == 12) // speed - speed is always zero |