Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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-01-31-fix-fp-m9-3-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`M9-3-3`: `MemberFunctionConstIfPossible.ql`:
- Fix FP reported in 467. Excluding candidates in uninstantiated templates.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ class ConstMemberFunctionCandidate extends NonConstMemberFunction {
not this instanceof Destructor and
not this instanceof Operator and
//less interested in MemberFunctions with no definition
this.hasDefinition()
this.hasDefinition() and
// For uninstantiated templates we have only partial information that prevents us from determining
// if the candidate calls non-const functions. Therefore we exclude these.
not this.isFromUninstantiatedTemplate(_)
}

/**
Expand Down
26 changes: 26 additions & 0 deletions cpp/autosar/test/rules/M9-3-3/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,29 @@ class Z22 : Z1 {
void f2() final {} // COMPLIANT
void f3() { this->a = 100; } // COMPLIANT
};

template <class T> class Array {
public:
T &back();

private:
T data[128];
unsigned int size;
};

template <class T, template <class...> class U> class Stack {
public:
T &Top() {
return this->data.back();
} // Likely NON_COMPLIANT, but cannot be determined until instantiation.
Comment thread
rvermeulen marked this conversation as resolved.
Outdated
private:
U<T> data;
};

using IntVectorStack = Stack<int, Array>;

void test_template() {
IntVectorStack s;

int i = s.Top();
}