@@ -18,6 +18,7 @@ import cpp
18
18
import codingstandards.cpp.autosar
19
19
import codingstandards.cpp.LoggingOperation
20
20
import codingstandards.cpp.Literals
21
+ import codingstandards.cpp.Cpp14Literal
21
22
22
23
from Literal l
23
24
where
@@ -35,11 +36,11 @@ where
35
36
// Exclude literal 0
36
37
not l .getValue ( ) = "0" and
37
38
// Exclude character literals
38
- not l instanceof CharLiteral and
39
+ not l instanceof Cpp14Literal :: CharLiteral and
39
40
// Exclude `nullptr`
40
41
not l .getType ( ) instanceof NullPointerType and
41
42
// Exclude boolean `true` and `false`
42
- not l . getType ( ) instanceof BoolType and
43
+ not l instanceof BoolLiteral and
43
44
// Exclude empty string
44
45
not l .getValue ( ) = "" and
45
46
// Template functions use literals to represent calls which are unknown
51
52
// Aggregate literal
52
53
not l = any ( ArrayOrVectorAggregateLiteral aal ) .getAnElementExpr ( _) .getAChild * ( ) and
53
54
// Ignore x - 1 expressions
54
- not exists ( SubExpr se | se .getRightOperand ( ) = l and l .getValue ( ) = "1" )
55
- select l ,
56
- "Literal value " + getTruncatedLiteralText ( l ) + " used outside of type initialization " +
57
- l .getAPrimaryQlClass ( )
55
+ not exists ( SubExpr se | se .getRightOperand ( ) = l and l .getValue ( ) = "1" ) and
56
+ // Exclude compile time computed integral literals as they can appear as integral literals
57
+ // when used as non-type template arguments.
58
+ // We limit ourselves to integral literals, because floating point literals as non-type
59
+ // template arguments are not supported in C++ 14. Those are supported shince C++ 20.
60
+ not l instanceof CompileTimeComputedIntegralLiteral and
61
+ // Exclude literals to instantiate a class template per example in the standard
62
+ // where an type of std::array is intialized with size 5.
63
+ not l = any ( ClassTemplateInstantiation cti ) .getATemplateArgument ( ) and
64
+ not l = any ( ClassAggregateLiteral cal ) .getAFieldExpr ( _)
65
+ select l , "Literal value '" + getTruncatedLiteralText ( l ) + "' used outside of type initialization."
0 commit comments