rspec/rules/S5263/cfamily/rule.adoc

33 lines
782 B
Plaintext
Raw Normal View History

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 ``++|++``.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
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 '|'?
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
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)
include::message.adoc[]
endif::env-github,rspecator-view[]