...
This noncompliant code may result in an infinite-loop, instead of the expected behavior of looping through all enumeration values. The violation occurs at the end of the loop, when e1 = static_cast<e1>(E_G+1), which is out-of-range.
Code Block | ||
---|---|---|
| ||
enum et1 { E_A = 1, E_B, E_C, E_D, E_E, E_F, E_G }; for(et1 e1 = E_A; e1 <= E_G; e1 = static_cast<e1>(e1+1)) { /* some action */ } |
...