mardi 23 février 2021

How to avoid Klockwork warning on initialization and assignment in C++

I am running static code analysis and found an interesting warning that come from following checkers: https://lpdkklocwork01vm.bmwgroup.net:8081/documentation/help/reference/VA_UNUSED.GEN.htm https://lpdkklocwork01vm.bmwgroup.net:8081/documentation/help/reference/VA_UNUSED.INIT.htm

For the below code snippet I get warnings as specified in the code. Is there a workaround to implement following code to resolve warnings?

void foo(void)
{
    int var = 0; // Value of "var" never used after initialization
    if(/*some_condition*/) var = 10; // Value of "var" never used after assignment
    else var = 20; // Value of "var" never used after assignment
    return var;
}

Aucun commentaire:

Enregistrer un commentaire