This rule is part of MISRA C++:2023.
Usage of this content is governed by Sonar’s terms and conditions. Redistribution is
prohibited.
Rule 13.3.3 - The parameters in all declarations [1] or overrides of a function shall either be unnamed or have identical names
Category: Required
Analysis: Decidable,System
Rationale
The name given to a parameter helps document the purpose of the parameter. If a function parameter is renamed in a subsequent declaration
[1], then having different names for the same object may lead to developer confusion.
Example
The following example is compliant:
void fn1( int32_t a );
void fn1( int32_t );
The following example is non-compliant as the parameter names have been swapped:
void CreateRectangle( uint32_t Height, uint32_t Width );
void CreateRectangle( uint32_t Width, uint32_t Height );
The following example is non-compliant as the named parameters are different:
void fn2( int32_t a );
void fn2( int32_t b ) { }
The following example is non-compliant as the parameter name in the override differs from the parameter name in the overridden function:
class Shape
{
virtual void draw( Canvas & destination ) = 0;
};
class Rectangle : public Shape
{
void draw( Canvas & canvas ) override;
};
The rule does not apply to the following example as the specialization is a different declaration [1] (note that this example is
non-compliant with M23_184: MISRA C++ 2023 Rule 17.8.1):
template< class T > void f( T t );
template<> void f< int32_t >( int32_t i );
Glossary
[1] 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 [2]. All subsequent declarations are called redeclarations [3].
A definition [4] is a declaration, as described in [basic.def]/2.
[2] Introduction
See declaration [1].
[3] Redeclaration
See declaration [1].
[4] Definition
See declaration [1].
Copyright The MISRA Consortium Limited © 2023