Skip to content

Commit 5235b0b

Browse files
committed
A5-2-6: Improve alert message
Attempt to clarify which expression is to be parenthesized
1 parent 2b909fb commit 5235b0b

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- `A5-2-6` - `OperandsOfAlogicalAndOrNotParenthesized.ql`:
2-
- Remove false positives where the operator is identical.
2+
- Remove false positives where the operator is identical.
3+
- Improve alert message to clarify which expression needs to be parenthesized.

cpp/autosar/src/rules/A5-2-6/OperandsOfALogicalAndOrNotParenthesized.ql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@
1717
import cpp
1818
import codingstandards.cpp.autosar
1919

20-
from BinaryLogicalOperation op, BinaryOperation binop
20+
from BinaryLogicalOperation op, BinaryOperation binop, string leftOrRight
2121
where
2222
not isExcluded(op, OrderOfEvaluationPackage::operandsOfALogicalAndOrNotParenthesizedQuery()) and
23-
op.getAnOperand() = binop and
23+
(
24+
op.getLeftOperand() = binop and
25+
leftOrRight = "Left"
26+
or
27+
op.getRightOperand() = binop and
28+
leftOrRight = "Right"
29+
) and
2430
// Ignore cases with the same operator
2531
not op.getOperator() = binop.getOperator() and
2632
not exists(ParenthesisExpr p | p = binop.getFullyConverted()) and
2733
// Exclude binary operations expanded by a macro.
2834
not binop.isInMacroExpansion()
29-
select op, "Binary $@ operand of logical operation is not parenthesized.", binop, "operator"
35+
select op, "$@ of logical operation " + op.getOperator() + " is not parenthesized.", binop,
36+
leftOrRight + " operand " + binop.getOperator()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:3:7:3:23 | ... && ... | Binary $@ operand of logical operation is not parenthesized. | test.cpp:3:7:3:12 | ... > ... | operator |
2-
| test.cpp:3:7:3:23 | ... && ... | Binary $@ operand of logical operation is not parenthesized. | test.cpp:3:17:3:23 | ... < ... | operator |
3-
| test.cpp:7:7:7:24 | ... \|\| ... | Binary $@ operand of logical operation is not parenthesized. | test.cpp:7:19:7:24 | ... > ... | operator |
1+
| test.cpp:3:7:3:23 | ... && ... | $@ of logical operation && is not parenthesized. | test.cpp:3:7:3:12 | ... > ... | Left operand > |
2+
| test.cpp:3:7:3:23 | ... && ... | $@ of logical operation && is not parenthesized. | test.cpp:3:17:3:23 | ... < ... | Right operand < |
3+
| test.cpp:7:7:7:24 | ... \|\| ... | $@ of logical operation \|\| is not parenthesized. | test.cpp:7:19:7:24 | ... > ... | Right operand > |

0 commit comments

Comments
 (0)