AUTOSAR C++14 Rule A6-5-3
Do statements should not be used
Description
Rule Definition
Do statements should not be used.
Rationale
A do statement can introduce bugs in your code because its
termination condition is checked after executing the code block. Consider this code where an
array is accessed by using a pointer in a do-while
loop.
int* array;
//...
do {
cout<<*array;
--array;
} while (array != nullptr); Avoid do statements in your code. You can use do
statements to write function-like macros.
Polyspace Implementation
Polyspace® flags all do statements, except those located in
macros.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Statements |
| Category: Advisory, Automated |
Version History
Introduced in R2020b