Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V1048. Variable 'foo' was assigned...
menu mobile close menu
Additional information
toggle menu Contents

V1048. Variable 'foo' was assigned the same value.

Oct 18 2019

The analyzer has detected a case where a variable is assigned the value already stored in it. Such an assignment is very likely to be a logic error.

Consider the following example:

int i = foo();
if (i == 0)
{
  i = 0;      // <=
}

The reported assignment does not change the value of the variable, and the code is apparently faulty.

The analyzer can also detect cases where exact values of variables are unknown:

void foo(int x, int y)
{
  if (x == y)
  {
    x = y;    // <=
  }
}

Even though the variables 'x' and 'y' can take any values, the assignment is still meaningless because of the earlier condition checking these variables for equality.

This diagnostic is classified as:

You can look at examples of errors detected by the V1048 diagnostic.