@@ -18,6 +18,7 @@ import cpp
1818import codingstandards.cpp.autosar
1919import codingstandards.cpp.LoggingOperation
2020import codingstandards.cpp.Literals
21+ import codingstandards.cpp.Cpp14Literal
2122
2223from Literal l
2324where
@@ -35,11 +36,11 @@ where
3536 // Exclude literal 0
3637 not l .getValue ( ) = "0" and
3738 // Exclude character literals
38- not l instanceof CharLiteral and
39+ not l instanceof Cpp14Literal :: CharLiteral and
3940 // Exclude `nullptr`
4041 not l .getType ( ) instanceof NullPointerType and
4142 // Exclude boolean `true` and `false`
42- not l . getType ( ) instanceof BoolType and
43+ not l instanceof BoolLiteral and
4344 // Exclude empty string
4445 not l .getValue ( ) = "" and
4546 // Template functions use literals to represent calls which are unknown
5152 // Aggregate literal
5253 not l = any ( ArrayOrVectorAggregateLiteral aal ) .getAnElementExpr ( _) .getAChild * ( ) and
5354 // 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