File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -69,8 +69,8 @@ class NumericType extends Type {
69
69
}
70
70
71
71
predicate isAssignment ( Expr source , NumericType targetType , string context ) {
72
- // Assignment operator
73
- exists ( Assignment assign |
72
+ // Assignment operator (but not compound assignment)
73
+ exists ( AssignExpr assign |
74
74
assign .getRValue ( ) = source and
75
75
context = "assignment"
76
76
|
@@ -191,7 +191,7 @@ predicate hasConstructorException(FunctionCall call) {
191
191
*/
192
192
class IdExpression extends VariableAccess {
193
193
IdExpression ( ) {
194
- // Not a member variable
194
+ // Not a member variable access (no dot or arrow)
195
195
(
196
196
not exists ( this .getQualifier ( ) )
197
197
or
Original file line number Diff line number Diff line change @@ -359,4 +359,25 @@ void test_references() {
359
359
std::uint64_t l4 = 1000 ;
360
360
std::uint64_t &l5 = l4;
361
361
f14 (l5); // NON_COMPLIANT - narrowing conversion through reference
362
+ }
363
+
364
+ // Test compound assignments - rule does not apply to compound assignments
365
+ void test_compound_assignments () {
366
+ std::uint8_t l1 = 10 ;
367
+ std::uint16_t l2 = 100 ;
368
+ std::int8_t l3 = 5 ;
369
+ float l4 = 1 .5f ;
370
+
371
+ l1 += l2; // COMPLIANT - compound assignment, rule does not apply
372
+ l1 -= l3; // COMPLIANT - compound assignment, rule does not apply
373
+ l2 *= l1; // COMPLIANT - compound assignment, rule does not apply
374
+ l2 /= l3; // COMPLIANT - compound assignment, rule does not apply
375
+ l1 %= l3; // COMPLIANT - compound assignment, rule does not apply
376
+ l2 &= l1; // COMPLIANT - compound assignment, rule does not apply
377
+ l2 |= l3; // COMPLIANT - compound assignment, rule does not apply
378
+ l2 ^= l1; // COMPLIANT - compound assignment, rule does not apply
379
+ l2 <<= 2 ; // COMPLIANT - compound assignment, rule does not apply
380
+ l2 >>= 1 ; // COMPLIANT - compound assignment, rule does not apply
381
+ l4 += l1; // COMPLIANT - compound assignment, rule does not apply
382
+ l4 -= s32; // COMPLIANT - compound assignment, rule does not apply
362
383
}
You can’t perform that action at this time.
0 commit comments