Modify rule S5263: add diff view and add documentation links

This commit is contained in:
Amelie Renard 2023-10-05 09:58:05 +02:00 committed by Amélie Renard
parent 8c40222b3c
commit 020f1d2f98

View File

@ -1,27 +1,31 @@
== 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 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 ``++|++``.
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]
[source,cpp,diff-id=1,diff-type=noncompliant]
----
int fun(int a) {
return a || 4; // Noncompliant, did you mean to use bitwise operator '|'?
return a || 4; // Noncompliant: did you mean to use bitwise operator '|'?
}
----
=== Compliant solution
[source,cpp]
[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[]