V587. An odd sequence of assignments of this kind: A = B; B = A;.


Analyzer detected a potential error concerning the senseless mutual assignment of variables.

Let's review an example:

int A, B, C;
...
A = B;
C = 10;
B = A;

Here the assignment "B=A" lacks any sort of practical utility. It is possibly a misprint or just an unnecessary operation. The correct code:

A = B;
C = 10;
B = A_2;

An example stated above is a synthetic one. Let's see how such an error could appear in the source code of a real-life application:

// Swap; exercises counters
{
  RCPFooRef temp = f2;
  f2 = f3;
  f3 = f2;
}

The correct code:

// Swap; exercises counters
{
  RCPFooRef temp = f2;
  f2 = f3;
  f3 = temp;
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;