I am running static code analysis and found warnings.
For the below code snippet I get warnings as specified in the code. Is there a workaround to implement following code to resolve warnings?
int foo(bool cond)
{
int var = 0; // Value of "var" never used after initial
if(cond){
var = 10; // Value of "var" never used after assignment
}
else{
var = 20; // Value of "var" never used after assignment
}
return var;
}
void main(){
cout << foo(true);
return;
}
The obvious thing to do is to remove the initial dead assignment:
Or (better), eliminate the variable entirely: