AUTOSAR C++14 Rule A7-3-1
All overloads of a function shall be visible from where it is called
Description
Rule Definition
All overloads of a function shall be visible from where it is called.
Rationale
If all overloads of a function are not visible, a developer or code reviewer might expect an incorrect overload when a function is called. For instance, suppose a using
declaration occurs between the definitions of two overloads of a function validateInput()
:
namespace initialTests { void validateInput(uint16_t input); } using initialTests::validateInput; namespace initialTests { void validateInput(uint32_t input); //Noncompliant }
validateInput()
is called, only the overload that occurs before the using
declaration is in scope for call resolution. However, a developer might expect both overloads to be in scope and pick the incorrect overload.Polyspace Implementation
The rule checker reports a violation in only one of two cases identified in the rule specifications:
The checker reports a violation if a function is declared in a namespace after these two events:
Another overload of the function has been previously declared in the same namespace.
A
using
declaration has already exposed that name to function call resolution.
The checker does not report a violation when an implementation of a function in a derived class hides the base class implementation of the same function.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Declaration |
Category: Required, Automated |
Version History
Introduced in R2019a