Skip to content

Commit 00d36a7

Browse files
committed
Exclude bool literals and char literals instead of types
Bool literals do not always have a bool type so we exclude them using the bool literal class. We exclude using the char literal class to reduce duplication and increase coverage in case of new char literals.
1 parent 28ac4c1 commit 00d36a7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import cpp
6+
import codingstandards.cpp.Cpp14Literal
67

78
/** Gets `Literal.getValueText()` truncated to at most 20 characters. */
89
string getTruncatedLiteralText(Literal l) {
@@ -36,10 +37,12 @@ class Utf32StringLiteral extends StringLiteral {
3637
class CompileTimeComputedIntegralLiteral extends Literal {
3738
CompileTimeComputedIntegralLiteral() {
3839
this.getUnspecifiedType() instanceof IntegralType and
39-
not this.getUnspecifiedType() instanceof BoolType and
40-
not this.getUnspecifiedType() instanceof CharType and
41-
// In some cases we still type char constants like '.' as int
42-
not this.getValueText().trim().matches("'%'") and
40+
// Exclude bool, whose value text is true or false, but the value itself
41+
// is 1 or 0.
42+
not this instanceof BoolLiteral and
43+
// Exclude character literals, whose value text is the quoted character, but the value
44+
// is the numeric value of the character.
45+
not this instanceof Cpp14Literal::CharLiteral and
4346
not this.getValueText()
4447
.trim()
4548
.regexpMatch("([0-9][0-9']*|0[xX][0-9a-fA-F']+|0b[01']+)[uU]?([lL]{1,2}|[zZ])?") and

0 commit comments

Comments
 (0)