rspec/rules/S5263/cfamily/rule.adoc

38 lines
864 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
While working with bitwise operators ``++&++`` or ``++|++`` it is easy to make a typo and write the equivalent logical operators ``++&&++`` or ``++||++``. This rule is raising issues when the right operand of a logical expression ``++&&++`` or ``++||++`` is a constant of integral type, as the developer probably meant to use the corresponding bitwise operator ``++&++`` or ``++|++``.
=== 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
----
int fun(int a) {
return a || 4; // Noncompliant, did you mean to use bitwise operator '|'?
}
----
=== 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
----
int fun(int a) {
return a | 4;
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Review this logical (&& | ||) expression with constant operand.
endif::env-github,rspecator-view[]