Skip to content

Commit eb13914

Browse files
committed
Exclude boolean literals used as non-type template arguments
1 parent 5bbe64c commit eb13914

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cpp/autosar/src/rules/A5-1-1/LiteralValueUsedOutsideTypeInit.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ where
3939
// Exclude `nullptr`
4040
not l.getType() instanceof NullPointerType and
4141
// Exclude boolean `true` and `false`
42-
not l.getType() instanceof BoolType and
42+
not l instanceof BoolLiteral and
4343
// Exclude empty string
4444
not l.getValue() = "" and
4545
// Template functions use literals to represent calls which are unknown

cpp/common/src/codingstandards/cpp/Literals.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ class CompileTimeComputedIntegralLiteral extends Literal {
4747
not any(ConstructorFieldInit cfi).getExpr() = this
4848
}
4949
}
50+
51+
class BoolLiteral extends Literal {
52+
BoolLiteral() {
53+
this.getType() instanceof BoolType
54+
or
55+
// When used as non-type template arguments, bool literals might
56+
// have been converted to a non-bool type.
57+
this.getValue() = "1" and this.getValueText() = "true"
58+
or
59+
this.getValue() = "0" and this.getValueText() = "false"
60+
}
61+
}

0 commit comments

Comments
 (0)