Main Content

AUTOSAR C++14 Rule M8-0-1

An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or member-declarator respectively

Description

Rule Definition

An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or member-declarator respectively.

Rationale

Init-declarator-lists that have multiple declarators might result in ambiguous type assignments and might cause a developer to assign unintended types to certain identifiers. Having a single init-declarator for each declaration clarifies the declaration type and reduces the risk of unwanted type assignments. Avoid multiple declarators in an init-declarator-list or a member-declarator-list.

Polyspace Implementation

Polyspace® flags declarators after the first declarator in an init-declarator-list or a member-declarator-list.

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 <cstdint> 
#include <string> 

class exampleClass{}; 

void foo() { 
    double a, b, c; //Noncompliant 
    exampleClass objectOne, objectTwo; //Noncompliant 
    int32_t d; int32_t e; //Compliant 
    std::string f;  //Compliant  
}

In this example, Polyspace flags init-declarator-lists that have multiple declarators. For instance:

  • double a, b, c is noncompliant because the init-declarator-list consists of more than one init-declarator and the b and c declarators are flagged.

  • exampleClass objectOne, objectTwo is noncompliant because the init-declarator-list consists of more than one init-declarator and the objectTwo declarator is flagged.

  • int32_t d, int32_t e and std::string f are compliant because each init-declarator-list consists of a single init-declarator.

Check Information

Group: Declarators
Category: Required, Automated

Version History

Introduced in R2019a