42 lines
1.1 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
While working with bitwise operators ``++&++`` or ``++|++``, it is easy to make a typo and write the equivalent logical operators ``++&&++`` or ``++||++``. This rule raises an issue 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
[source,cpp,diff-id=1,diff-type=noncompliant]
----
int fun(int a) {
return a || 4; // Noncompliant: did you mean to use bitwise operator '|'?
}
----
=== Compliant solution
[source,cpp,diff-id=1,diff-type=compliant]
----
int fun(int a) {
return a | 4;
}
----
== Resources
* {cpp} reference - https://en.cppreference.com/w/cpp/language/operator_arithmetic#Bitwise_logic_operators[Bitwise logic operators]
* {cpp} reference - https://en.cppreference.com/w/cpp/language/operator_logical[Logical operators]
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[]