Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V3008. The 'x' variable is assigned val…
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Micro-Optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C++)
OWASP errors (C#)
Problems related to code analyzer
Additional information
toggle menu 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.

close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

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

close form
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

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

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam