Main Content

AUTOSAR C++14 Rule A7-1-7

Each expression statement and identifier declaration shall be placed on a separate line

Description

Rule Definition

Each expression statement and identifier declaration shall be placed on a separate line.

Rationale

In C++, you can place several statements on the same line, or declare multiple identifiers in the same statement. However, doing so might interfere with readability. For instance, declaring several identifiers on the same line might make it difficult to locate the declarations later.

Polyspace Implementation

The checker raises a violation when two consecutive declaration or expression statements are on the same line (unless the statements are part of a macro definition).

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

#include <cstdbool>

extern bool checkForBounds(int); 

bool func(int arg) {
    int x = arg, y = arg, z;                 //Noncompliant 
    x++; y--;                                //Noncompliant
    z = checkForBounds(x) && checkForBounds(y);   //Compliant
    return z;                                     //Compliant
}

In this example, the first two lines in function func() are noncompliant because they either have multiple declarations or multiple expressions on the same line.

Check Information

Group: Declaration
Category: Required, Automated

Version History

Introduced in R2019a