The function chosen by overload resolution shall resolve to a function declared previously in the translation unit
The function chosen by overload resolution shall resolve to a function declared previously in the translation unit.
In general, you cannot call a function before it is declared, so you expect a function call to resolve to a previously declared function. However, in case of overload resolution of a function call inside a template, this expectation might not be satisfied. The resolution of this overload occurs at the point of template instantiation, not at the point of template definition. So, the call might resolve to a function that is declared after the template definition and lead to unexpected results. See examples below.
To satisfy the expectation that a function call always
resolves to a previously declared function, declare the overloads of a function
prior to calling it. Alternatively, use the scope resolution operator
:: or parenthesis to explicitly call a specific previously
declared function and bypass the overload resolution mechanism.
The checker flags a call to a function or operator in a function template definition if the function or operator is declared after the template definition.
If you expect a rule violation but do not see it, refer to the documentation for Polyspace® Code Prover™ or Polyspace Code Prover Server™.
| Group: Templates |
| Category: Required |