diff --git a/change_notes/2024-01-26-exclusion-a5-0-2.md b/change_notes/2024-01-26-exclusion-a5-0-2.md new file mode 100644 index 0000000000..33d8113774 --- /dev/null +++ b/change_notes/2024-01-26-exclusion-a5-0-2.md @@ -0,0 +1,2 @@ +`A5-0-2` - `NonBooleanIfStmt.qll`, `NonBooleanIterationStmt.qll`: + - Exclude compiler generated conditions. \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll b/cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll index 18346a8159..bd84597a44 100644 --- a/cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll +++ b/cpp/common/src/codingstandards/cpp/rules/nonbooleanifstmt/NonBooleanIfStmt.qll @@ -14,6 +14,8 @@ query predicate problems(Expr condition, string message) { not isExcluded(condition, getQuery()) and exists(IfStmt ifStmt, Type explicitConversionType | condition = ifStmt.getCondition() and + //exclude any generated conditions + not condition.isCompilerGenerated() and not ifStmt.isFromUninstantiatedTemplate(_) and explicitConversionType = condition.getExplicitlyConverted().getUnderlyingType() and not explicitConversionType instanceof BoolType and diff --git a/cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll b/cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll index f1ee555406..c342811c52 100644 --- a/cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll +++ b/cpp/common/src/codingstandards/cpp/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.qll @@ -16,6 +16,8 @@ query predicate problems(Loop loopStmt, string message) { condition = loopStmt.getCondition() and explicitConversionType = condition.getExplicitlyConverted().getType().getUnspecifiedType() and not explicitConversionType instanceof BoolType and + //exclude any generated conditions + not condition.isCompilerGenerated() and message = "Iteration condition has non boolean type " + explicitConversionType + "." ) }