Main Content

AUTOSAR C++14 Rule A7-1-8

A non-type specifier shall be placed before a type specifier in a declaration

Since R2020a

Description

Rule Definition

A non-type specifier shall be placed before a type specifier in a declaration.

Rationale

Non-type specifiers include:

  • typedef.

  • friend.

  • constexpr.

  • register.

  • static.

  • extern.

  • thread-local.

  • mutable.

  • inline.

  • virtual.

  • explicit.

To make the code more readable, place non-type specifiers before type specifiers in a declaration.

Polyspace Implementation

Polyspace® flags declarations that place non-type specifiers after a type specifier. If more than one non-type specifiers follow a type specifier, Polyspace flags the rightmost non-type specifier.

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

The following example demonstrate the Polyspace implementation of AUTOSAR rule A7-1-8.

#include <cstdint>

typedef std::int32_t int1;  // Compliant
std::int32_t typedef int2;  // Noncompliant

class to_be_friend
{
    explicit to_be_friend(int); // Compliant
    static void* foo(void);     // Compliant
    void static* bar(void);     // Noncompliant
    virtual inline void i1(void) {}; // Compliant
    inline void virtual i2(void) {}; // Noncompliant
    constexpr static long long l1 = 0; // Compliant
    long long constexpr static l3 = 0; //Noncompliant
};
main()
{
    //...
}

Polyspace flags declarations where you place non-type specifiers after type-specifiers. The declaration of the static object l3 is flagged because the non-type specifiers static and constexpr are placed after the type-specifier long long. The violation is highlighted on the rightmost non-type specifier, which is static.

Check Information

Group: Declaration
Category: Required, Automated

Version History

Introduced in R2020a