checkUnreachableCode(): fix FP for statements that just hide compiler warnings about unused function arguments

Seen throughout the rockbox codebase.
This commit is contained in:
Thomas Jarosch 2014-12-22 11:15:22 +01:00
parent 10ae551fef
commit d5e10c18d3
2 changed files with 38 additions and 1 deletions

View File

@ -1189,7 +1189,23 @@ void CheckOther::checkUnreachableCode()
}
}
}
if (!labelInFollowingLoop)
// hide FP for statements that just hide compiler warnings about unused function arguments
bool silencedCompilerWarningOnly = false;
const Token *silencedWarning = secondBreak;
for (;;) {
if (Token::Match(silencedWarning, "( void ) %var% ;")) {
silencedWarning = silencedWarning->tokAt(5);
continue;
} else if (silencedWarning && silencedWarning == scope->classEnd)
silencedCompilerWarningOnly = true;
break;
}
if (silencedWarning)
secondBreak = silencedWarning;
if (!labelInFollowingLoop && !silencedCompilerWarningOnly)
unreachableCodeError(secondBreak, inconclusive);
tok = Token::findmatch(secondBreak, "[}:]");
} else

View File

@ -2965,6 +2965,27 @@ private:
"}", 0, false, false, false, false);
ASSERT_EQUALS("[test.cpp:3]: (style) Statements following return, break, continue, goto or throw will never be executed.\n", errout.str());
check("int foo(int unused) {\n"
" return 0;\n"
" (void)unused;\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("", errout.str());
check("int foo(int unused1, int unused2) {\n"
" return 0;\n"
" (void)unused1;\n"
" (void)unused2;\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("", errout.str());
check("int foo(int unused1, int unused2) {\n"
" return 0;\n"
" (void)unused1;\n"
" (void)unused2;\n"
" foo();\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("[test.cpp:5]: (style) Statements following return, break, continue, goto or throw will never be executed.\n", errout.str());
check("int foo() {\n"
" if(bar)\n"
" return 0;\n"