A reference is used on both sides of compound assignment operator

  • REDUNDANT_COMPOUND_ASSIGN
  • Error
  • Medium
  • No tags

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

View with compliant examples side by side
// Example 1
x -= x - y;

// Example 2
x += x + y;

Compliant Code Example

View with noncompliant examples side by side
// 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

Was this documentation helpful?