Skip to content

Commit 4d804eb

Browse files
authored
Merge pull request #519 from rvermeulen/rvermeulen/fix-467
Fix FP reported in #467
2 parents 4cc31a6 + 99e9fdb commit 4d804eb

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M9-3-3`: `MemberFunctionConstIfPossible.ql`:
2+
- Fix FP reported in 467. Excluding candidates in uninstantiated templates.

cpp/autosar/src/rules/M9-3-3/MemberFunctionConstIfPossible.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ class ConstMemberFunctionCandidate extends NonConstMemberFunction {
5454
not this instanceof Destructor and
5555
not this instanceof Operator and
5656
//less interested in MemberFunctions with no definition
57-
this.hasDefinition()
57+
this.hasDefinition() and
58+
// For uninstantiated templates we have only partial information that prevents us from determining
59+
// if the candidate calls non-const functions. Therefore we exclude these.
60+
not this.isFromUninstantiatedTemplate(_)
5861
}
5962

6063
/**

cpp/autosar/test/rules/M9-3-3/test.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@ class Z22 : Z1 {
162162
void f3() { this->a = 100; } // COMPLIANT
163163
};
164164

165+
template <class T> class Array {
166+
public:
167+
T &back();
168+
169+
private:
170+
T data[128];
171+
unsigned int size;
172+
};
173+
174+
template <class T, template <class...> class U> class Stack {
175+
public:
176+
T &Top() {
177+
return this->data.back();
178+
} // COMPLIANT[FALSE_NEGATIVE|TRUE_NEGATIVE] - exception not specified in the
179+
// standard, we opt to not raise an issue because the template can be both
180+
// compliant and non-compliant depending on instantiations.
181+
private:
182+
U<T> data;
183+
};
184+
185+
using IntVectorStack = Stack<int, Array>;
186+
187+
void test_template() {
188+
IntVectorStack s;
189+
190+
int i = s.Top();
191+
}
192+
165193
class Z3 {
166194
void f(int) = delete; // COMPLIANT
167-
};
195+
};

0 commit comments

Comments
 (0)