From 020f1d2f98d671237a8ea60066c68dfdce8287d7 Mon Sep 17 00:00:00 2001 From: Amelie Renard Date: Thu, 5 Oct 2023 09:58:05 +0200 Subject: [PATCH] Modify rule S5263: add diff view and add documentation links --- rules/S5263/cfamily/rule.adoc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rules/S5263/cfamily/rule.adoc b/rules/S5263/cfamily/rule.adoc index 8af5fcc55a..ba5a3aec3e 100644 --- a/rules/S5263/cfamily/rule.adoc +++ b/rules/S5263/cfamily/rule.adoc @@ -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[]