Main Content

MISRA C++:2023 Rule 13.3.3

The parameters in all declarations or overrides of a function shall either be unnamed or have identical names

Since R2024b

Description

Rule Definition

The parameters in all declarations or overrides of a function shall either be unnamed or have identical names.

Rationale

The parameter names of a function typically convey how the parameters are used within the function body. Redeclarations or overrides of a function are not expected to change how the parameters are used by the function. Using different parameter names for function redeclarations or overrides can make the code confusing to read.

Polyspace Implementation

Polyspace® tracks the declaration and definition of functions during compilation and reports a violation if all of these conditions are true:

  • A function or a class member function has more than one declaration or override.

  • The declarations or overrides use the same numbers and types of parameters.

  • The redeclarations or overrides use mismatched parameter names.

The checker also reports a violation if the definition of a function diverges from the function declaration solely in the name of a parameter.

This rule does not apply to function overloads. If you declare a function without using any parameter names, redeclaring the function with parameter names does not cause a violation 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

In this example, the class Derived redeclares the function setDimensions(float length, float width) using different parameter names. Polyspace reports a defect. Overloading this function using two integer parameters does not violate this rule.

class Base {
public:
	double Area() {
		return length * width;
	}
	void setDimensions(float length, float width);
protected:
	float length;
	float width;
};

class Derived : public Base {
public:
	void setDimensions(float width, float length); //Noncompliant -
	//Redefines setDimensions with different parameter names

	void setDimensions(int w, int l); //Compliant - rule does not apply to overloads.
};

Check Information

Group: Derived Classes
Category: Required

Version History

Introduced in R2024b