Skip to content

Commit f484080

Browse files
committed
Exclude user-defined literals and templates
1 parent 850a1d5 commit f484080

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

cpp/common/src/codingstandards/cpp/Cpp14Literal.qll

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ module Cpp14Literal {
77
private import cpp as StandardLibrary
88

99
/** An numeric literal. */
10-
abstract class NumericLiteral extends StandardLibrary::Literal { }
10+
abstract class NumericLiteral extends StandardLibrary::Literal {
11+
NumericLiteral() {
12+
// exclude user-defined literals as they define custom suffixes
13+
not exists(StandardLibrary::FunctionCall fc |
14+
this = fc.getArgument(0) and fc.getTarget().getName().matches("operator \"\"%")
15+
) and
16+
// exclude literals derived from template instantiations
17+
not this.isFromTemplateInstantiation(_)
18+
}
19+
}
1120

1221
/** Convenience for implementing class `UnrecognizedNumericLiteral` */
1322
abstract private class RecognizedNumericLiteral extends StandardLibrary::Literal { }
@@ -49,7 +58,7 @@ module Cpp14Literal {
4958
* Octal literals must always start with the digit `0`.
5059
*/
5160
class OctalLiteral extends IntegerLiteral, RecognizedNumericLiteral {
52-
OctalLiteral() { getValueText().regexpMatch("\\s*0[0-7']+[uUlL]*\\s*") }
61+
OctalLiteral() { getValueText().regexpMatch("\\s*0[0-7']*[uUlL]*\\s*") }
5362

5463
override string getAPrimaryQlClass() { result = "OctalLiteral" }
5564
}

0 commit comments

Comments
 (0)