Main Content

MISRA C++:2008 Rule 8-4-2

The identifiers used for the parameters in a re-declaration of a function shall be identical to those in the declaration

Description

Rule Definition

The identifiers used for the parameters in a re-declaration of a function shall be identical to those in the declaration.1

Rationale

Using different identifiers in redeclarations can cause developer confusion. Using the same parameter identifiers in a function declaration and a function redeclaration helps make code easier to understand, maintain, and document.

Polyspace Implementation

The checker detects mismatch in parameter names between:

  • A function declaration and the corresponding function definition.

  • Two declarations of a function in the same file.

    If the declarations occur in different files, the checker does not report a violation for mismatch in parameter names. Declaring the same function in different files is a violation of MISRA C++:2008 Rule 3-2-3.

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 code, the redeclaration of the function sumValues() uses the parameters int x and int y instead of the parameters int sumA and int sumB from the original declaration. In this instance, using the parameters int sumA and int sumB in the redeclaration makes the code compliant with this rule.

void sumValues(int sumA, int sumB);

void sumValues(int x, int y) { 	//Noncompliant
    int sum = x + y;
}

int main() {
	
    //...
    return 0;
}

Check Information

Group: Declarators
Category: Required

Version History

Introduced in R2013b


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.