2023-08-03 09:11:13 +02:00

69 lines
1.3 KiB
Plaintext

== 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
[source,cpp,diff-id=1,diff-type=noncompliant]
----
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
[source,cpp,diff-id=1,diff-type=compliant]
----
switch (i) {
case 0:
//...
break;
case 1 ... 2:
//...
break;
case 3 ... 5
//...
break;
----
== Resources
=== Documentation
* GCC - https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html[Case Ranges]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Reverse or otherwise refactor this range; it doesn't match any value.
=== Highlighting
``++x...y++``
endif::env-github,rspecator-view[]