2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
The GNU compiler extension that allows ``++case++``s to be specified with ranges should only be used when a range is actually needed. Use it with the same number on both ends of the range, and you've either made a mistake because an actual range was intended, or you've used the syntax inappropriately in a way that is highly likely to confuse maintainers.
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
switch (i) {
case 0:
//...
break;
case 1 ... 2:
//...
break;
case 3 ... 3: // Noncompliant
//...
break;
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
switch (i) {
case 0:
//...
break;
case 1 ... 2:
//...
break;
case 3:
//...
break;
}
----
or
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
switch (i) {
case 0:
//...
break;
case 1 ... 2:
//...
break;
case 3 ... 5:
//...
break;
}
----
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Update this range to cover more than one value or refactor it to remove the range syntax.
=== Highlighting
``++x ... x++``
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]