File tree 3 files changed +43
-5
lines changed
3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change 17
17
import cpp
18
18
import codingstandards.cpp.autosar
19
19
20
- from Expr e
21
- where
22
- not isExcluded ( e , OrderOfEvaluationPackage:: insufficientUseOfParenthesesQuery ( ) )
23
- select e , "Insufficient use of parenthesis in expression."
20
+ class InsufficientlyParenthesizedExpr extends Expr {
21
+ InsufficientlyParenthesizedExpr ( ) {
22
+ exists ( BinaryOperation root , BinaryOperation child | child = this |
23
+ root .getAnOperand ( ) = child and
24
+ root .getOperator ( ) != child .getOperator ( ) and
25
+ not any ( ParenthesisExpr pe ) .getExpr ( ) = child
26
+ )
27
+ or
28
+ exists ( ConditionalExpr root , BinaryOperation child | child = this |
29
+ root .getAnOperand ( ) = child and
30
+ not any ( ParenthesisExpr pe ) .getExpr ( ) = child
31
+ )
32
+ }
33
+ }
34
+
35
+ from InsufficientlyParenthesizedExpr e
36
+ where not isExcluded ( e , OrderOfEvaluationPackage:: insufficientUseOfParenthesesQuery ( ) )
37
+ select e , "Dependence on operator precedence rules."
Original file line number Diff line number Diff line change 1
- No expected results have yet been specified
1
+ | test.cpp:40:8:40:13 | ... * ... | Dependence on operator precedence rules. |
2
+ | test.cpp:41:19:41:24 | ... * ... | Dependence on operator precedence rules. |
3
+ | test.cpp:42:8:42:13 | ... * ... | Dependence on operator precedence rules. |
4
+ | test.cpp:42:17:42:22 | ... * ... | Dependence on operator precedence rules. |
5
+ | test.cpp:48:8:48:15 | ... == ... | Dependence on operator precedence rules. |
6
+ | test.cpp:49:26:49:32 | ... - ... | Dependence on operator precedence rules. |
7
+ | test.cpp:50:8:50:15 | ... == ... | Dependence on operator precedence rules. |
8
+ | test.cpp:50:24:50:30 | ... - ... | Dependence on operator precedence rules. |
Original file line number Diff line number Diff line change @@ -31,4 +31,21 @@ void f1() {
31
31
int **l7;
32
32
l1 = (*l7)[l2]; // NON_COMPLIANT[FALSE_NEGATIVE]
33
33
char l8 = (char )(l1 + 1 ); // NON_COMPLIANT[FALSE_NEGATIVE]
34
+ }
35
+
36
+ void test_insufficient_parentheses () {
37
+ int l1, l2, l3;
38
+
39
+ l1 = (2 * l2) + (3 * l3); // COMPLIANT
40
+ l1 = 2 * l2 + (3 * l3); // NON_COMPLIANT
41
+ l1 = (2 * l2) + 3 * l3; // NON_COMPLIANT
42
+ l1 = 2 * l2 + 3 * l3; // NON_COMPLIANT
43
+ l1 = (2 * l2) + l3 + 1 ; // COMPLIANT
44
+ l1 = (l2 + 1 ) - (l2 + l3); // COMPLIANT
45
+ l1 = l2 + l3 + 1 ; // COMPLIANT
46
+
47
+ l1 = (l2 == l3) ? l2 : (l2 - l3); // COMPLIANT
48
+ l1 = l2 == l3 ? l2 : (l2 - l3); // NON_COMPLIANT
49
+ l1 = (l2 == l3) ? l2 : l2 - l3; // NON_COMPLIANT
50
+ l1 = l2 == l3 ? l2 : l2 - l3; // NON_COMPLIANT
34
51
}
You can’t perform that action at this time.
0 commit comments