rspec/rules/S3936/cfamily/rule.adoc

74 lines
1.1 KiB
Plaintext
Raw Normal View History

== 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.
=== 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;
}
----
=== 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;
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Update this range to cover more than one value or refactor it to remove the range syntax.
=== Highlighting
``++x ... x++``
endif::env-github,rspecator-view[]