Main Content

AUTOSAR C++14 Rule A7-1-6

The typedef specifier shall not be used

Description

Rule Definition

The typedef specifier shall not be used.

Rationale

The using syntax is a better alternative to typedef-s for defining aliases.

Since C++11, the using syntax allows you to define template aliases where the template arguments are not bound to a data type. For instance, the following statements define an alias vectorType for vector, where the argument T is not bound to a data type and can be substituted later:

template<class T, class Allocator = allocator<T>> class vector;
template<class T> using vectorType = vector<T, My_allocator<T>>;
vectorType<int> primes = {2,3,5,7,11,13,17,19,23,29};
The typedef keyword does not allow defining such template aliases.

Polyspace Implementation

The rule checker flags all uses of the typedef keyword.

If you do not want to remove certain instances of the typedef keyword, add a comment justifying those results. See:

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 <type_traits>

typedef std::int32_t (*fptr1) (std::int32_t); //Noncompliant
using fptr2 = std::int32_t (*) (std::int32_t); //Compliant

template <class T> using fptr3 = std::int32_t (*) (T); //Compliant

The alias definitions for fptr1 and fptr2 are exactly equivalent. There is no typedef equivalent for the alias definition for fptr3.

The use of typedef-s violates this rule. The rule requires that you stick to the using syntax for consistency even when a typedef equivalent exists.

Check Information

Group: Declaration
Category: Required, Automated

Version History

Introduced in R2019a