Why is this an issue?
The GNU compiler gives the possibility to specify a range of consecutive values in a case
label, for example: case: 1 ...
5
.
However, if the values are written in decreasing order, i.e., from the larger value to the smaller one, the range will evaluate as empty. So the
case
body will never be executed.
How to fix it
The rule raises an issue when a range specified in a case
label is in decreasing order. Swap the values to define a valid range.
Code examples
Noncompliant code example
switch (i) {
case 0:
//...
break;
case 1 ... 2:
//...
break;
case 5 ... 3: // Noncompliant: it evaluates as empty, so the code will never be executed
//...
break;
Compliant solution
switch (i) {
case 0:
//...
break;
case 1 ... 2:
//...
break;
case 3 ... 5
//...
break;
Resources
Documentation