Main Content

AUTOSAR C++14 Rule A0-1-4

There shall be no unused named parameters in non-virtual functions

Description

Rule Definition

There shall be no unused named parameters in non-virtual functions.

Rationale

Unused parameters can indicate that the code is possibly incomplete. For example, if you intended to use a parameter in a specific operation, but you did not code the operation due to a design change, your code does not use the parameter.

If the parameters are obtained by copy and the copied objects are large, the redundant copies can slow down performance.

Polyspace Implementation

The checker flags a function that has unused named parameters unless the function body is empty.

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 Body contains two functions (femur and bmi), which both take two parameters (x and y). The function bmi uses both parameters. However, the code does not use the parameter y within the body of the function femur.

class Body {
public:
    double femur(double x, double y) {     //Noncompliant
        return x * 0.2674;
    }

    double bmi(double x, double y) {       //Compliant
        double bmi = ((y / (x * x)) * 703); 
        return bmi;
    }
};

int main()
{
    double height = 72;
    double weight = 185;
    Body example;

    example.femur(height, weight);
    example.bmi(height, weight);

    return 0;
}

If the unused parameter y indicates a programming error and you want to use the parameter, fix the error. Otherwise, remove the unused parameter.

Check Information

Group: Language Independent Issues
Category: Required, Automated

Version History

Introduced in R2019a

expand all