checkUnreachableCode(): fix FP for statements that just hide compiler warnings about unused function arguments
Seen throughout the rockbox codebase.
This commit is contained in:
parent
10ae551fef
commit
d5e10c18d3
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue