Our website uses cookies to enhance your browsing experience.
Accept
to the top
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

Webinar: C++ semantics - 06.11

>
>
>
V6123. Modified value of the operand is…
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#)
Problems related to code analyzer
Additional information
toggle menu Contents

V6123. Modified value of the operand is not used after the increment/decrement operation.

Oct 22 2024

The analyzer has detected that the value of the postfix operation is not used. Most likely, either the operation is superfluous, or a prefix operation should be used instead of a postfix operation.

Example:

int calculateSomething() {
  int value = getSomething();
  ....
  return value++;
}

In this example, there is a local variable 'value'. The method is expected to return its incremented value. However, according to JLS:

The value of the postfix increment expression is the value of the variable before the new value is stored.

Thus, the '++' operator will have no effect on the value returned by the 'calculateSomething' method. Possible corrected option:

int calculateSomething() {
  int value = getSomething();
  ....
  return ++value;
}

The following option of corrected code emphasizes even better that the returned value must be greater by one:

int calculateSomething() {
  int value = getSomething();
  ....
  return value + 1;
}

We recommend using the second option, as it is easier to comprehend.

Another synthetic example:

void foo() {
  int value = getSomething();
  bar(value++);
  bar(value++);
  bar(value++);
}

Each time the 'bar' method is called with an argument greater by one. The last increment does not make sense, since the increased value of the variable is not used further. However, there is no error here, since the last increment is written for aesthetic reasons. No warning will be issued if a variable is incremented sequentially more than two times in a row.

However, we still recommend writing as follows:

void foo() {
  int value = getSomething();
  bar(value++);
  bar(value++);
  bar(value);
}

Another possible option:

void foo() {
  int value = getSomething();
  bar(value + 0);
  bar(value + 1);
  bar(value + 2);
}

This diagnostic is classified as: