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

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:

```cpp
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](https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.14.2):

> 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:

```cpp
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:

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

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

Another synthetic example:

```cpp
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:

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

Another possible option:

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