Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions change_notes/2024-06-03-constexpr-variable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `A7-1-2` - `VariableMissingConstexpr.ql`:
- Remove false positives for compiler generated variables
Comment thread
lcartey marked this conversation as resolved.
Outdated
- Remove results in uninstantiated templates that cause false positives
6 changes: 5 additions & 1 deletion 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
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: 12 additions & 0 deletions cpp/autosar/test/rules/A7-1-2/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,16 @@ 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>();
}