AUTOSAR C++14 Rule A2-10-5
An identifier name of a function with static storage duration or a non-member object with external or internal linkage should not be reused
Since R2020b
Description
Rule Definition
An identifier name of a function with static storage duration or a non-member object with external or internal linkage should not be reused.
Rationale
Objects with static storage duration remain available during the entire execution of the program. These include:
Non-member objects with external linkage that can be referred to from any of the translation units of your project.
Objects declared with the
static
class specifier. These objects have internal linkage and can be referred to from any scope within their translation unit.
If you reuse the name of an identifier, you might mistake one identifier for the other.
The rule does not apply to objects with no linkage, for instance function local static objects, since the identifiers of those objects cannot be referred to from outside of their scope.
Polyspace Implementation
When you reuse identifiers, Polyspace® flags the last use of the identifier if they are in the same translation unit. If the identifiers are in separate files, the identifier in the last file path by alphabetical order is flagged.
If you declare a function in a namespace with the
static
class specifier and reuse the function identifier to declare a non-static function in another namespace, Polyspace flags the identifier of the static function. For instance, in this code snippet, the identifierfunc
is reused in namespaceNS_2
but it is flagged in namespaceNS_1
.namespace NS_1 { static void func(void); // Polyspace flags this use of "func". }; namespace NS_2 { void func(void); //"func" identifier reused but this is not a static function. }
Polyspace flags the identifier of a global variable if you reuse the identifier for a local variable.
Polyspace does not flag the reuse of an identifier for global functions and their arguments that are declared without the
static
class specifier.
The checker is not raised on unused code such as
Noninstantiated templates
Uncalled
static
orextern
functionsUncalled and undefined local functions
Unused types and variables
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: Lexical conventions |
Category: Advisory, Automated |
Version History
Introduced in R2020b