To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
V3008. The 'x' variable is assigned val…
Analyzer diagnostics
Additional information
Contents

V3008. The 'x' variable is assigned values twice successively. Perhaps this is a mistake.

Nov 18 2015

The analyzer has detected an error that has to do with assigning values to one and the same variable twice in a row, while this variable is not used in any way between the assignments.

Consider this example:

A = GetA();
A = GetB();

The 'A' variable being assigned values twice might indicate a bug. The code should have most probably looked like this:

A = GetA();
B = GetB();

Cases when the variable is used between the assignments are treated as correct and do not trigger the warning:

A = 1;
A = Foo(A);

The following is an example of the bug taken from a real-life application:

....
if (bool.TryParse(setting, out value))
    _singleSignOn = value;
_singleSignOn = false;
....

A correct version of this code should look like this:

....
if (bool.TryParse(setting, out value))
    _singleSignOn = value;
else
    _singleSignOn = false;
....

The analyzer might output false positives sometimes. This happens when such variable assignments are used for debugging purposes. For example:

status = Foo1();
status = Foo2();

The false positive in this code can be handled in a number of ways:

  • You can suppress it by inserting comment "//-V3008".
  • You can forbid the analyzer to output diagnostic V3008 for any case where variable 'status' is used. To do that, insert comment "//-V:status:3008".
  • You can remove idle assignments from the code.
  • Perhaps this code is incorrect, so we have to check the value of the 'status' variable.

This diagnostic is classified as:

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

This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept