Skip to content

Commit d2cdde7

Browse files
authored
Merge pull request github#543 from rvermeulen/rvermeulen/fix-10
Address FP reported in #10
2 parents 17d73e4 + 32434d7 commit d2cdde7

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `A5-0-2` - `NonBooleanIterationCondition.ql`:
2+
- Address FP reported in #10. Exclude conditions in uninstantiated templates.
3+
- `M5-3-1` - `EachOperandOfTheOperatorTheLogicalAndOrTheLogicalOperatorsShallHaveTypeBool.ql`:
4+
- Adjust the alert message to comply with the style guide.

cpp/autosar/src/rules/M5-3-1/EachOperandOfTheOperatorTheLogicalAndOrTheLogicalOperatorsShallHaveTypeBool.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ where
2929
rt = t.getUnderlyingType().getUnspecifiedType() and rt.getBaseType() instanceof BoolType
3030
) and
3131
not operand.isFromUninstantiatedTemplate(_)
32-
select operand, "bool operator called with a non-bool operand of type " + t.getName() + "."
32+
select operand, "Call to bool operator with a non-bool operand of type '" + t.getName() + "'."
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:10:8:10:8 | 0 | bool operator called with a non-bool operand of type int. |
2-
| test.cpp:12:7:12:7 | 0 | bool operator called with a non-bool operand of type int. |
3-
| test.cpp:12:13:12:17 | ... + ... | bool operator called with a non-bool operand of type int. |
1+
| test.cpp:10:8:10:8 | 0 | Call to bool operator with a non-bool operand of type 'int'. |
2+
| test.cpp:12:7:12:7 | 0 | Call to bool operator with a non-bool operand of type 'int'. |
3+
| test.cpp:12:13:12:17 | ... + ... | Call to bool operator with a non-bool operand of type 'int'. |

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Provides a library which includes a `problems` predicate for reporting....
2+
* Provides a library which includes a `problems` predicate for reporting non-boolean iteration conditions.
33
*/
44

55
import cpp
@@ -16,8 +16,10 @@ query predicate problems(Loop loopStmt, string message) {
1616
condition = loopStmt.getCondition() and
1717
explicitConversionType = condition.getExplicitlyConverted().getType().getUnspecifiedType() and
1818
not explicitConversionType instanceof BoolType and
19-
//exclude any generated conditions
19+
// 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/nonbooleanifstmt/test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,16 @@ void test_boolean_conditions() {
4646
if (a) { // COMPLIANT - a has an explicit operator bool()
4747
}
4848
}
49+
50+
template <typename T> bool test_fp_reported_in_10a(T &p1) {
51+
if (p1.length() > 10) { // COMPLIANT
52+
return true;
53+
}
54+
return false;
55+
}
56+
57+
#include <string>
58+
void test_fp_reported_in_10b() {
59+
std::string s;
60+
test_fp_reported_in_10a(s);
61+
}

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)