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
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¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
allow_auto_with_explicit_cast¶
allow_auto_with_explicit_cast : bool = False
auto to declare variables, when the variable is initialized
with an explicit cast.
allow_for_loop_counter¶
allow_for_loop_counter : bool = False
auto is used to declare a for-loop counter.
allow_generic_lambda_parameters¶
allow_generic_lambda_parameters : bool = True
allow_nonfundamental_initializer¶
allow_nonfundamental_initializer : bool = True
allow_template_instance¶
allow_template_instance : bool = False
auto stands for a template instance.
allowed_contexts¶
allowed_contexts : set[typing.Callable[[Auto_Type_Selection], bool]] = set()
auto is allowed.
allowed_types¶
allowed_types : set[bauhaus.ir.LIR_Class_Name | typing.Pattern[str] | typing.Callable[[Type], bool]] = set()
auto is allowed, given as name pattern,
function, or LIR class name.