Skip to content

Commit 2ec2814

Browse files
committed
Rule 7.0.6: Support functions with default parameters
Overload independence should consider what parameters are default.
1 parent 916fb3d commit 2ec2814

File tree

3 files changed

+144
-128
lines changed

3 files changed

+144
-128
lines changed

cpp/misra/src/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.ql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ predicate isNonExtensible(Call c) {
119119
c.getTarget() instanceof Operator
120120
}
121121

122+
int getMinimumNumberOfParameters(Function f) {
123+
result = count(Parameter p | p = f.getAParameter() and not p.hasInitializer() | p)
124+
}
125+
122126
predicate isOverloadIndependent(Call call, Expr arg) {
123127
arg = call.getAnArgument() and
124128
(
@@ -135,7 +139,10 @@ predicate isOverloadIndependent(Call call, Expr arg) {
135139
// so check the templates overloads
136140
overload = target.(FunctionTemplateInstantiation).getTemplate().getAnOverload()
137141
) and
138-
overload.getNumberOfParameters() = call.getNumberOfArguments() and
142+
// Check that the overload accepts the number of arguments provided by this call,
143+
// considering parameters with default values may be omitted in the call
144+
overload.getNumberOfParameters() >= call.getNumberOfArguments() and
145+
getMinimumNumberOfParameters(overload) <= call.getNumberOfArguments() and
139146
call.getArgument(i) = arg
140147
|
141148
// Check that the parameter types match

0 commit comments

Comments
 (0)