AutosarC++17_10-A5.1.1

Literal values shall not be used apart from type initialization, otherwise symbolic names shall be used instead

Required inputs: IR

Possible Messages

Key

Text

Severity

Disabled

magic_number

Use of magic literal.

None

False

magic_number_without_token

Use of magic literal.

None

False

magic_string

Use of magic string literal.

None

False

possible_magic_number

Potential use of magic literal.

None

False

Options

allow_nonconst_variable_initialization

allow_nonconst_variable_initialization : bool = False

If set to true, allow string literals in the initialization of variables, even if the variable is not const. This option only applies to the initialization as part of the variable declaration, not to any later assignments.
 

allowed

allowed : set[float] = {0.0, 1.0, 2.0}

Literal values that are ok.
 

allowed_contexts

allowed_contexts

Type: set[bauhaus.ir.PIR_Class_Name | typing.Callable[[bauhaus.ir.Node], bool]]

Default: {'Template_Const_Argument', <function bauhaus.rules.autosar.cpp.rule_A5_1_1.allow_in_type_initialization(node)>}

Optional set of PIR classes or functions ((node) -> bool) for allowed contexts, e.g. Case_Label.
 

allowed_logging_contexts

allowed_logging_contexts : set[bauhaus.analysis.config.QualifiedName] = {'std::basic_ostream'}

List of fully qualified function types that are considered logging contexts (using operator<<). If this is non-empty, std::throw() is considered a valid logging context as well.
 

allowed_string_contexts

allowed_string_contexts

Type: set[bauhaus.ir.PIR_Class_Name | typing.Callable[[bauhaus.ir.Node], bool]]

Default: {<function bauhaus.rules.autosar.cpp.rule_A5_1_1.allow_in_type_initialization(node)>}

Optional set of PIR classes or functions ((node) -> bool) for allowed contexts.
 

allowed_strings

allowed_strings : set[str] = {' ', ''}

Literal values that are ok.
 

exceptions

exceptions : typing.Callable[[bauhaus.ir.Node], bool] | None = None

Optional predicate to filter out cases that should be allowed as an exception. The predicate takes a literal node and returns True if the given node is such an exception.
 

exclude_pp_literals

exclude_pp_literals : bool = True

If true, literals in conditions of #if are ignored.
 

exclude_single_uses

exclude_single_uses : bool = False

If true, report only literals used more than once.