summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2019-10-30 13:35:20 -0400
committerAaron Ballman <aaron@aaronballman.com>2019-10-30 13:38:25 -0400
commit1caa66d0759f6bd0851a40645afac8e8a7f84341 (patch)
treedb2f9a20987ea4e9c3f699b012bf3bf922357aa1 /clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
parent21d498c9c0f32dcab5bc89ac593aa813b533b43a (diff)
downloadbcm5719-llvm-1caa66d0759f6bd0851a40645afac8e8a7f84341.tar.gz
bcm5719-llvm-1caa66d0759f6bd0851a40645afac8e8a7f84341.zip
Fix a false positive in misc-redundant-expression check
Do not warn for redundant conditional expressions when the true and false branches are expanded from different macros even when they are defined by one another. Patch by Daniel Krupp.
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
index f6b47eb79fb..500478159a4 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -114,6 +114,7 @@ int Valid(int X, int Y) {
#define COND_OP_MACRO 9
#define COND_OP_OTHER_MACRO 9
+#define COND_OP_THIRD_MACRO COND_OP_MACRO
int TestConditional(int x, int y) {
int k = 0;
k += (y < 0) ? x : x;
@@ -122,11 +123,27 @@ int TestConditional(int x, int y) {
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'true' and 'false' expressions are equivalent
k += (y < 0) ? COND_OP_MACRO : COND_OP_MACRO;
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: 'true' and 'false' expressions are equivalent
+ k += (y < 0) ? COND_OP_MACRO + COND_OP_OTHER_MACRO : COND_OP_MACRO + COND_OP_OTHER_MACRO;
+ // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: 'true' and 'false' expressions are equivalent
// Do not match for conditional operators with a macro and a const.
k += (y < 0) ? COND_OP_MACRO : 9;
// Do not match for conditional operators with expressions from different macros.
k += (y < 0) ? COND_OP_MACRO : COND_OP_OTHER_MACRO;
+ // Do not match for conditional operators when a macro is defined to another macro
+ k += (y < 0) ? COND_OP_MACRO : COND_OP_THIRD_MACRO;
+#undef COND_OP_THIRD_MACRO
+#define COND_OP_THIRD_MACRO 8
+ k += (y < 0) ? COND_OP_MACRO : COND_OP_THIRD_MACRO;
+#undef COND_OP_THIRD_MACRO
+
+ k += (y < 0) ? sizeof(I64) : sizeof(I64);
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: 'true' and 'false' expressions are equivalent
+ k += (y < 0) ? sizeof(TestConditional(k,y)) : sizeof(TestConditional(k,y));
+ // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: 'true' and 'false' expressions are equivalent
+ // No warning if the expression arguments are different.
+ k += (y < 0) ? sizeof(TestConditional(k,y)) : sizeof(Valid(k,y));
+
return k;
}
#undef COND_OP_MACRO
@@ -134,7 +151,7 @@ int TestConditional(int x, int y) {
// Overloaded operators that compare two instances of a struct.
struct MyStruct {
- int x;
+ int x;
bool operator==(const MyStruct& rhs) const {return this->x == rhs.x; } // not modifing
bool operator>=(const MyStruct& rhs) const { return this->x >= rhs.x; } // not modifing
bool operator<=(MyStruct& rhs) const { return this->x <= rhs.x; }
OpenPOWER on IntegriCloud