Skip to content

Commit 5f90fae

Browse files
committed
Exclude literals used in class template instantiation
1 parent b19874a commit 5f90fae

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ where
5252
not l = any(ArrayOrVectorAggregateLiteral aal).getAnElementExpr(_).getAChild*() and
5353
// Ignore x - 1 expressions
5454
not exists(SubExpr se | se.getRightOperand() = l and l.getValue() = "1") and
55-
not l instanceof CompileTimeComputedIntegralLiteral
55+
not l instanceof CompileTimeComputedIntegralLiteral and
56+
// Exclude literals to instantiate a class template per example in the standard
57+
// where an type of std::array is intialized with size 5.
58+
not l = any(ClassTemplateInstantiation cti).getATemplateArgument()
5659
select l,
5760
"Literal value " + getTruncatedLiteralText(l) + " used outside of type initialization " +
5861
l.getAPrimaryQlClass()

cpp/autosar/test/rules/A5-1-1/LiteralValueUsedOutsideTypeInit.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
| test.cpp:104:8:104:8 | 4 | Literal value 4 used outside of type initialization Literal |
77
| test.cpp:104:8:104:8 | 4 | Literal value 4 used outside of type initialization Literal |
88
| test.cpp:104:8:104:8 | 4 | Literal value 4 used outside of type initialization Literal |
9-
| test.cpp:108:18:108:18 | 1 | Literal value 1 used outside of type initialization Literal |

cpp/autosar/test/rules/A5-1-1/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ template <typename T, int size> struct S2 {
105105
};
106106

107107
void test_fp_reported_in_371() {
108-
struct S2<int, 1> l1; // COMPLIANT[FALSE_POSITIVE]
108+
struct S2<int, 1> l1; // COMPLIANT
109109
struct S2<int, g1> l2; // COMPLIANT
110110
struct S2<int, f1()> l3; // COMPLIANT
111111
}

0 commit comments

Comments
 (0)