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 {
6969}
7070
7171predicate 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 |
7474 assign .getRValue ( ) = source and
7575 context = "assignment"
7676 |
@@ -191,7 +191,7 @@ predicate hasConstructorException(FunctionCall call) {
191191 */
192192class IdExpression extends VariableAccess {
193193 IdExpression ( ) {
194- // Not a member variable
194+ // Not a member variable access (no dot or arrow)
195195 (
196196 not exists ( this .getQualifier ( ) )
197197 or
Original file line number Diff line number Diff line change @@ -359,4 +359,25 @@ void test_references() {
359359 std::uint64_t l4 = 1000 ;
360360 std::uint64_t &l5 = l4;
361361 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
362383}
You can’t perform that action at this time.
0 commit comments