Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

53 lines
1.2 KiB
Plaintext

== Why is this an issue?
loop-control-variables are either the loop-counter, or flags used for early loop termination. The code is easier to understand if these are not modified within condition or expression.
=== Noncompliant code example
[source,cpp]
----
for ( x = 0; ( x < 10 ) && !bool_a; ++x )
{
if ( ... )
{
bool_a = true; // Compliant
}
}
bool test_a ( bool * pB )
{
*pB = ... ? true : false;
return *pB;
}
for ( x = 0; ( x < 10 ) && test_a ( &bool_a ); ++x ) // Noncompliant, 'bool_a' modified in the condition
volatile bool status;
for ( x = 0; ( x < 10 ) && status; ++x) // Compliant
for ( x = 0; x < 10; bool_a = test( ++x ) ) // Noncompliant, bool_a modified in the expression.
----
=== Exceptions
Note that it is possible for a loop-control-variable with volatile qualification to change value (or have it changed) outside statement due to the volatile nature of the object. Such modification does not break this rule.
== Resources
* MISRA {cpp}:2008, 6-5-5
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== duplicates: S886
=== relates to: S892
=== is related to: S886
endif::env-github,rspecator-view[]