C++: Add testcase demonstrating false positive

This commit is contained in:
Mathias Vorreiter Pedersen
2020-01-07 11:35:54 +01:00
parent 7e84453ec9
commit 428e357488
2 changed files with 22 additions and 0 deletions

View File

@@ -13,3 +13,6 @@
| test.cpp:82:7:82:11 | ... = ... | Use of '=' where '==' may have been intended. |
| test.cpp:84:7:84:11 | ... = ... | Use of '=' where '==' may have been intended. |
| test.cpp:92:17:92:22 | ... = ... | Use of '=' where '==' may have been intended. |
| test.cpp:105:6:105:10 | ... = ... | Use of '=' where '==' may have been intended. |
| test.cpp:113:6:113:10 | ... = ... | Use of '=' where '==' may have been intended. |
| test.cpp:113:6:113:10 | ... = ... | Use of '=' where '==' may have been intended. |

View File

@@ -98,3 +98,22 @@ void g(int *i_p, int cond) {
if (y = 1) { // GOOD: y might not be initialized so it is probably intentional.
}
}
template<typename>
void h() {
int x;
if(x = 0) { // GOOD [FALSE POSITIVE]: x is not initialized so this is probably intensional
}
int y = 0;
if((y = 1)) { // GOOD
}
int z = 0;
if(z = 1) { // BAD
}
}
void f() {
h<int>();
}