Main Content

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

If an identifier refers to a type, it shall not also refer to an object or a function in the same scope

Description

Rule Definition

If an identifier refers to a type, it shall not also refer to an object or a function in the same scope.

Rationale

To maintain compatibility with C code, the C++ standard allows you to use the same name for a type and an object or function. However, the name reuse can cause confusion during development or code review.

Polyspace Implementation

Polyspace® reports a violation of this rule if you use an identifier both as a type name and as a function or object name. If the identifier is a function name and the function is both declared and defined, then the violation is reported once.

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

struct vector{
    int x;
    int y;
    int z;
}vector; //Noncompliant

In this example, the name vector is used both for the structured data type and for an object of that type.

Check Information

Group: Lexical Conventions
Category: Required

Version History

Introduced in R2013b