AUTOSAR C++14 Rule A2-10-4
The identifier name of a non-member object with static storage duration or static function shall not be reused within a namespace
Since R2020b
Description
Rule Definition
The identifier name of a non-member object with static storage duration or static function shall not be reused within a namespace.
Rationale
You use namespaces to narrow the scope of the identifiers that you declare within these namespaces. This prevents these identifiers from being mistaken with identical identifiers in other scopes. If you reuse an identifier with static storage duration within the same namespace across source files, you might mistake one identifier for the other.
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.
However, if you reuse an identifier but declare only one instance of the identifier with the keyword
static
, that identifier is flagged regardless of the order in which the identifiers are declared.Polyspace raises no violation if you declare an identifier in a namespace and you reuse that identifier in the same namespace, but within a nested or inlined namespace. For instance, no violation is raised on
reusedVar
in this code snippet.//file1.cpp namespace foo { static int reusedVar; //resuedVar has static storage duration } //file2.cpp namespace foo { void func(); namespace nested_foo { float reusedVar; } inline namespace inlined_foo { char reusedVar; } }
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: Required, Automated |
Version History
Introduced in R2020b