AutosarC++18_10-A6.5.4

For-init-statement and expression should not perform actions other than loop-counter initialization and modification

Required inputs: IR

Rationale

If only a loop-counter is used in the for-init-statement and expression, it increases readability and it is easier to understand and maintain code.

Example
// $Id: A6-5-4.cpp 305629 2018-01-29 13:29:25Z piotr.serwa $
    #include <cstdint>

    void Fn() noexcept
    {
        for (std::int32_t x = 0, MAX=10; x < MAX; x++)        // compliant with A6-5-2, butnon-compliant with advisory A6-5-4
        {
            // ...
        }
    }
See Also
  • JSF December 2005 [8]: AV Rule 198: The initialization expression in a for loop will perform no actions other than to initialize the value of a single for loop parameter.
  • JSF December 2005 [8]: AV Rule 199: The increment expression in a for loop will perform no action other than to change a single loop parameter to the next value for the loop.

Possible Messages

Key

Text

Severity

Disabled

loop_side_effect

Side effect in loop init/expression.

None

False

non_loop_counter_initialized

Non loop counter initialized.

None

False

non_loop_counter_modified

Non loop counter modified.

None

False

Options

loop_counter_model

loop_counter_model

Type: LoopCounterModel

Default: 'misra_cpp_2008'

The loop counter model on which the analysis is based.
 

Option Types

These types are used by options listed above:

LoopCounterModel

  • misra_c_2004

  • misra_c_2004_continue

  • misra_c_2012

  • misra_c_2012_continue

  • misra_cpp_2008

  • cert

  • generic