Skip to content

Commit f7617ab

Browse files
authored
Merge pull request #22727 from geoffw0/qualitytests
C++: Fill gaps in query tests (part 1)
2 parents ae74161 + bef877a commit f7617ab

6 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
| empty_block.cpp:9:10:9:11 | { ... } | Empty block without comment. |
22
| empty_block.cpp:12:10:13:3 | { ... } | Empty block without comment. |
33
| empty_block.cpp:20:10:21:3 | { ... } | Empty block without comment. |
4+
| empty_block.cpp:84:14:85:3 | { ... } | Empty block without comment. |
5+
| empty_block.cpp:93:10:94:3 | { ... } | Empty block without comment. |
6+
| empty_block.cpp:99:10:100:3 | { ... } | Empty block without comment. |
7+
| empty_block.cpp:100:10:101:3 | { ... } | Empty block without comment. |

‎cpp/ql/test/query-tests/Best Practices/Likely Errors/EmptyBlock/empty_block.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,25 @@ int f(int x) {
8080
}
8181
}
8282

83+
// BAD
84+
if (x > 1) {
85+
}
86+
87+
// GOOD
88+
if (x) {
89+
++x;
90+
}
91+
92+
// DUBIOUS (reported)
93+
if (x) {
94+
} else {
95+
++x;
96+
}
97+
98+
// BAD (x2)
99+
if (x) {
100+
} else {
101+
}
102+
83103
return 1;
84104
}

‎cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ int extreme_values(void)
4343
if (y >> 1 >= 0x7FFFFFFFFFFF) {} // $ Alert[cpp/constant-comparison] // always true
4444
if (y >> 1 >= 0xFFFFFFFFFFF) {} // $ Alert[cpp/constant-comparison] // always true
4545
}
46+
47+
// Test for overlap between PointlessComparison and PointlessSelfComparison
48+
// (PointlessComparison should *not* report this)
49+
bool selfCmp1(int x) {
50+
return (x == (int)x);
51+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
void emptyIfs(int value) {
2+
if (value) {} // $ Alert[cpp/empty-if]
3+
4+
if (value > 1) {
5+
} // $ Alert[cpp/empty-if]
6+
7+
if (value) { // GOOD
8+
++value;
9+
}
10+
11+
if (value) { // GOOD
12+
} else {
13+
++value;
14+
}
15+
16+
if (value) { // $ MISSING: Alert[cpp/empty-if]
17+
} else {
18+
}
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| FutileConditional.cpp:2:3:2:15 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
2+
| FutileConditional.cpp:4:3:5:3 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Likely Bugs/Likely Typos/FutileConditional.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)