Skip to content

Commit da7e015

Browse files
committed
Added test and moved implementation_scope text
1 parent e6c25d3 commit da7e015

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

cpp/autosar/test/rules/M0-1-3/test.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void test_side_effect_init() {
4747
}
4848

4949
#include <cstdio>
50+
#include <array>
5051
template <int t>
5152
class CharBuffer
5253
{
@@ -55,13 +56,31 @@ class CharBuffer
5556
CharBuffer():member{0}{}
5657
};
5758

58-
int foo()
59+
int test_constexpr_in_template_inst()
5960
{
60-
constexpr int line_length = 1024U;
61+
constexpr int line_length = 1024U; // COMPLIANT - used in template inst.
62+
// of buffer.
6163
CharBuffer<line_length> buffer{};
62-
constexpr std::size_t max_stack_size_usage = 64 * 1024;
63-
static_assert(
64-
(sizeof(buffer) + sizeof(line_length)) <= max_stack_size_usage,
65-
"assert");
6664
return buffer.member[0];
6765
}
66+
67+
enum DataType : unsigned char {
68+
int8,
69+
int16,
70+
};
71+
72+
template <typename... Types>
73+
int test_constexpr_in_static_assert()
74+
{
75+
const std::array <DataType, sizeof...(Types)> lldts {int8};
76+
const std::array <DataType, sizeof...(Types)> llams {int16};
77+
constexpr std::size_t mssu = 64 * 1024; // COMPLIANT - used in static assert.
78+
static_assert((sizeof(lldts) + sizeof(llams)) <= mssu, "assert");
79+
return 0;
80+
}
81+
82+
int baz()
83+
{
84+
test_constexpr_in_static_assert<int>();
85+
return 0;
86+
}

rule_packages/cpp/DeadCode.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@
238238
"tags": [
239239
"readability",
240240
"maintainability"
241-
]
241+
],
242+
"implementation_scope": {
243+
"description": "In limited cases, this query can raise false-positives for variables that are defined as constexpr and used in an expression to instantiate a template."
244+
}
242245
},
243246
{
244247
"description": "Unused variables complicate the program and can indicate a possible mistake on the part of the programmer.",
@@ -344,4 +347,4 @@
344347
"title": "There shall be no dead code."
345348
}
346349
}
347-
}
350+
}

rule_packages/cpp/Templates.json

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -190,33 +190,6 @@
190190
}
191191
],
192192
"title": "In a class template with a dependent base, any name that may be found in that dependent base shall be referred to using a qualified-id or this->."
193-
},
194-
"M0-1-3": {
195-
"properties": {
196-
"allocated-target": [
197-
"implementation"
198-
],
199-
"enforcement": "automated",
200-
"obligation": "required"
201-
},
202-
"queries": [
203-
{
204-
"description": "Unused variables complicate the program and can indicate a possible mistake on the part of the programmer.",
205-
"kind": "problem",
206-
"name": "A project shall not contain unused local variables",
207-
"precision": "very-high",
208-
"severity": "warning",
209-
"short_name": "UnusedLocalVariable",
210-
"tags": [
211-
"maintainability",
212-
"readability"
213-
],
214-
"implementation_scope": {
215-
"description": "In limited cases, this query can raise false-positives for variables that are defined as constexpr and used in an expression to instantiate a template."
216-
}
217-
}
218-
],
219-
"title": "A project shall not contain unused local variables."
220193
}
221194
}
222195
}

0 commit comments

Comments
 (0)