This rule is part of MISRA C++:2023.
Usage of this content is governed by Sonar’s terms and conditions. Redistribution is
prohibited.
Rule 6.9.1 - The same type aliases shall be used in all declarations [2] of the same entity
Category: Required
Analysis: Decidable,Single Translation Unit
Rationale
If a redeclaration [1] uses different type aliases to those in its previous declarations [2], it may not be clear that the
declarations [2] refer to the same entity.
Example
typedef int32_t INT;
using Index = int32_t;
INT i;
extern int32_t i; // Non-compliant
INT j;
extern INT j; // Compliant
In the following, there are two declarations [2] of g, even though the types differ due to the top level const
qualifier:
void g( int32_t i );
void g( Index const i ); // Non-compliant - int32_t vs. Index
void h( Index i );
void h( Index const index ); // Compliant - Index used consistently
void h( int32_t * i ); // Rule does not apply - different overload
Glossary
[1] Redeclaration
See declaration [2].
[2] Declaration
A declaration introduces the name of an entity into a translation unit (see [basic.def]/1).
An entity may be declared several times. The first declaration of an entity in a translation unit is
called an introduction [3]. All subsequent declarations are called redeclarations [1].
A definition [4] is a declaration, as described in [basic.def]/2.
[3] Introduction
See declaration [2].
[4] Definition
See declaration [2].
Copyright The MISRA Consortium Limited © 2023