Why is this an issue?
Unnecessary casting expressions make the code harder to read and understand.
Noncompliant code example
int example(int i) {
int result = static_cast<int>(i + 42); // Noncompliant
return (int) result; // Noncompliant
}
Compliant solution
int example(int i) {
int result = i + 42;
return result;
}
Exceptions
In some rare cases, redundant cast might be justifiable. For example, when casting from platform dependant type; your cast might be redundant on
one platform but not on the others.