Skip to content

Commit 819e9f9

Browse files
committed
Exclude conditions in uninitialized templates
The type of conditions in uninitialized templates is unknown which leads to false positives.
1 parent d087031 commit 819e9f9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ query predicate problems(Loop loopStmt, string message) {
1818
not explicitConversionType instanceof BoolType and
1919
//exclude any generated conditions
2020
not condition.isCompilerGenerated() and
21+
// exclude any conditions in uninstantiated templates, because their type will be unknown.
22+
not condition.isFromUninstantiatedTemplate(_) and
2123
message = "Iteration condition has non boolean type " + explicitConversionType + "."
2224
)
2325
}

cpp/common/test/rules/nonbooleaniterationstmt/test.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,17 @@ class ClassC {
4141
if (!d.empty()) { // COMPLIANT
4242
}
4343
}
44-
};
44+
};
45+
46+
#include <vector>
47+
template <typename T> void test_fp_reported_in_10a(std::vector<T> &p1) {
48+
for (typename std::vector<T>::iterator it = p1.begin(); it != p1.end();
49+
++it) { // COMPLIANT
50+
(*it)++;
51+
}
52+
}
53+
54+
void test_fp_reported_in_10b() {
55+
std::vector<int> vl1;
56+
test_fp_reported_in_10a(vl1);
57+
}

0 commit comments

Comments
 (0)