AutosarC++18_10-A7.1.5

The auto specifier shall not be used apart from following cases: (1) to declare that a variable has the same type as return type of a function call, (2) to declare that a variable has the same type as initializer of non-fundamental type, (3) to declare parameters of a generic lambda expression, (4) to declare a function template using trailing return type syntax

Required inputs: IR

Do not use the auto type specifier introduced in C++11 (replacing the earlier automatic storage duration specifier). There are various options that allow auto for certain constructs.
Example
struct S{};
auto a = S{};   // bad
S b = S{};      // good

auto l = []{};  // ok with "allowed_types": ["Lambda_Class_Type"]

template
class C {};

auto c = C(); // ok with "allow_template_instance": true

Possible Messages

Key

Text

Severity

Disabled

cpp11_auto

Use of C++11 auto type specifier.

None

False

Options

allow_auto_with_explicit_cast

allow_auto_with_explicit_cast : bool = False

Allows auto to declare variables, when the variable is initialized with an explicit cast.
 

allow_for_loop_counter

allow_for_loop_counter : bool = False

Disables message if auto is used to declare a for-loop counter.
 

allow_generic_lambda_parameters

allow_generic_lambda_parameters : bool = True

Allows auto as parameter type in a generic lambda
 

allow_nonfundamental_initializer

allow_nonfundamental_initializer : bool = True

Allows auto to declare variables having a function call or initializer of non-fundamental type
 

allow_template_instance

allow_template_instance : bool = False

Disables message if auto stands for a template instance.
 

allowed_contexts

allowed_contexts : set[typing.Callable[[Auto_Type_Selection], bool]] = set()

Set of context predicates in which auto is allowed.
 

allowed_types

allowed_types : set[bauhaus.ir.LIR_Class_Name | typing.Pattern[str] | typing.Callable[[Type], bool]] = set()

Set of types for which auto is allowed, given as name pattern, function, or LIR class name.