Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/2026-10-26-fix-fp-rule-7-11-3-template-callee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `RULE-7-11-3` - `FunctionPointerConversionContext.ql`:
- Fixed false positives on unqualified calls to member and free functions inside class and function templates, where the callee is modelled as a function access that is the called expression of a call rather than a conversion to a function pointer.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class FunctionAccessConversionToFunctionPointer extends FunctionAccess,
FunctionToFunctionPointerConversion
{
FunctionAccessConversionToFunctionPointer() {
this.getType().getUnspecifiedType() instanceof FunctionPointerIshType
this.getType().getUnspecifiedType() instanceof FunctionPointerIshType and
// In templates, the callee of a dependent call is modelled as a function access that is the
// called expression of an ExprCall. This is a function call, not a conversion.
not any(ExprCall call).getExpr() = this
}
}

Expand Down
31 changes: 30 additions & 1 deletion cpp/misra/test/rules/RULE-7-11-3/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,33 @@ void test_logical_expressions() {
// Lambda used in logical OR expression
if (lam || false) { // NON_COMPLIANT
}
}
}
template <typename T> class TemplateWithMemberCalls {
public:
void callMembers() {
helper(); // COMPLIANT: callee of a call, not a conversion
this->helper(); // COMPLIANT
staticHelper(); // COMPLIANT
TemplateWithMemberCalls::staticHelper(); // COMPLIANT
}

auto takeAddress() {
return &TemplateWithMemberCalls::helper; // COMPLIANT: member pointer, not a
// function pointer
}

private:
void helper() {}
static void staticHelper() {}
};

template <typename T> void templateCallsFree() {
f(); // COMPLIANT
}

void instantiate() {
TemplateWithMemberCalls<int> t;
t.callMembers();
t.takeAddress();
templateCallsFree<int>();
}
Loading