Skip to content

Commit 29d0538

Browse files
committed
A7-1-2: Exclude generated variables and variables in uninstantiated templates.
1 parent fc282a6 commit 29d0538

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `A7-1-2` - `VariableMissingConstexpr.ql`:
2+
- Remove false positives for compiler generated variables
3+
- Remove results in uninstantiated templates that cause false positives

cpp/autosar/src/rules/A7-1-2/VariableMissingConstexpr.ql

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,9 @@ where
6262
// Not assigned by a user in a constructor
6363
not exists(ConstructorFieldInit cfi | cfi.getTarget() = v and not cfi.isCompilerGenerated()) and
6464
// Ignore union members
65-
not v.getDeclaringType() instanceof Union
65+
not v.getDeclaringType() instanceof Union and
66+
// Exclude variables in uninstantiated templates, as they may be incomplete
67+
not v.isFromUninstantiatedTemplate(_) and
68+
// Exclude compiler generated variables, which are not user controllable
69+
not v.isCompilerGenerated()
6670
select v, "Variable " + v.getName() + " could be marked 'constexpr'."

cpp/autosar/test/rules/A7-1-2/test.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,16 @@ constexpr void fp_reported_in_466(int p) {
264264
// compile time constant
265265
int l26 =
266266
add4(1, l3); // COMPLIANT - l3 is not compile time constant on all paths
267+
}
268+
269+
template <typename T> T* init(T** t) { }
270+
271+
template <typename T> T* init() {
272+
T* t = nullptr; // COMPLIANT - initialized below
273+
init(&t); // Init is ignored in uninitialized template
274+
return t;
275+
}
276+
277+
void test_template_instantiation() {
278+
int* t = init<int>();
267279
}

0 commit comments

Comments
 (0)