A reference is used on both sides of compound assignment operator

  • REDUNDANT_COMPOUND_ASSIGN
  • Error
  • Medium

This rule applies when a reference is used on both sides of compound assignment operator.

If there is a same reference on both sides of compound assignment operator, the compound operator applies to the reference itself.

It may be typo or intention. But it is recommended to use clearer and shorter code.

Noncompliant Code Example

// Example 1
x -= x - y;

// Example 2
x += x + y;

Compliant Code Example

// Example 1
x = y;
// or if typo
x = x - y;

// Example 2
x = 2*x + y;
// or if typo
x = x + y;

Version

This rule was introduced in DeepScan 1.8.0-beta.

See