Main Content

MISRA C++:2008 Rule 2-10-5

The identifier name of a non-member object or function with static storage duration should not be reused

Description

Rule Definition

The identifier name of a non-member object or function with static storage duration should not be reused.

Rationale

Reusing the name of an identifier with static storage duration makes the code confusing and difficult to maintain. You might use the wrong identifier in your code and introduce bugs that are difficult to fix.

The rule applies even if the identifiers belong to different namespaces because the reuse leaves the chance that you mistake one identifier for the other.

Polyspace Implementation

The rule flags situations where the name of an identifier with static storage duration is reused. The rule checker flags redefined functions only when there is a declaration.

The checker is not raised on unused code such as

  • Noninstantiated templates

  • Uncalled static or extern functions

  • Uncalled 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

expand all

namespace NS1 {
    static int WIDTH;
}

namespace NS2 {
    float WIDTH; //Noncompliant
}

In this example, the identifier name WIDTH is reused in the two namespaces NS1 and NS2.

Check Information

Group: Lexical Conventions
Category: Advisory

Version History

Introduced in R2013b

expand all