Main Content

MISRA C++:2023 Rule 6.9.1

The same type aliases shall be used in all declarations of the same entity

Since R2024b

Description

Rule Definition

The same type aliases shall be used in all declarations of the same entity.

Rationale

If a redeclaration uses different type aliases than the original declaration, then it is not clear that the two declaration refers to the same entity. To avoid confusion, use same type aliases when redeclaring an entity.

Polyspace Implementation

The rule checker compares the current declaration with the last seen declaration and reports a violation if the two declarations are not compatible. Differences in qualifiers such as const are not reported as violations of this rule.

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

typedef int* intptr;

int* map;
extern intptr map; //Noncompliant

intptr table;
extern intptr table; //Compliant

In this example, the variable map is declared twice. Because the two declaration of map uses two different aliases int* and intptr, Polyspace reports a violation. The two declaration of table uses the same alias intptr. Polyspace does not report a violation even though the two declaration differ by the token extern.

Check Information

Group: Basic Concepts
Category: Required

Version History

Introduced in R2024b