Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions change_notes/2024-06-03-constexpr-variable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A7-1-2` - `VariableMissingConstexpr.ql`:
- Fixes #607. Remove false positives for compiler generated variables and in uninstantiated templates
8 changes: 6 additions & 2 deletions cpp/autosar/src/rules/A7-1-2/VariableMissingConstexpr.ql
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ where
// Not assigned by a user in a constructor
not exists(ConstructorFieldInit cfi | cfi.getTarget() = v and not cfi.isCompilerGenerated()) and
// Ignore union members
not v.getDeclaringType() instanceof Union
select v, "Variable " + v.getName() + " could be marked 'constexpr'."
not v.getDeclaringType() instanceof Union and
// Exclude variables in uninstantiated templates, as they may be incomplete
not v.isFromUninstantiatedTemplate(_) and
// Exclude compiler generated variables, which are not user controllable
not v.isCompilerGenerated()
Comment thread
lcartey marked this conversation as resolved.
select v, "Variable '" + v.getName() + "' could be marked 'constexpr'."
12 changes: 11 additions & 1 deletion cpp/autosar/test/rules/A7-1-2/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,14 @@ constexpr void fp_reported_in_466(int p) {
// compile time constant
int l26 =
add4(1, l3); // COMPLIANT - l3 is not compile time constant on all paths
}
}
Comment thread
knewbury01 marked this conversation as resolved.

template <typename T> T *init(T **t) {}

template <typename T> T *init() {
T *t = nullptr; // COMPLIANT - initialized below
init(&t); // Init is ignored in uninitialized template
return t;
}

void test_template_instantiation() { int *t = init<int>(); }