avoid warning on first case (in case there are declarations before first case)

This commit is contained in:
Greg Hewgill 2011-02-23 22:45:21 +13:00
parent 1a606a57fd
commit 70fcbe94f4
2 changed files with 13 additions and 1 deletions

View File

@ -323,6 +323,7 @@ void CheckOther::checkSwitchCaseFallThrough()
std::stack<Token *> loopnest;
std::stack<Token *> scopenest;
bool justbreak = true;
bool firstcase = true;
for (const Token *tok2 = tok->tokAt(1)->link()->tokAt(2); tok2; tok2 = tok2->next())
{
if (Token::Match(tok2, "if ("))
@ -396,12 +397,13 @@ void CheckOther::checkSwitchCaseFallThrough()
}
else if (Token::Match(tok2, "case|default"))
{
if (!justbreak)
if (!justbreak && !firstcase)
{
switchCaseFallThrough(tok2);
}
tok2 = Token::findmatch(tok2, ":");
justbreak = true;
firstcase = false;
}
else if (tok2->str() == "{")
{

View File

@ -1383,6 +1383,16 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Switch falls through case without comment\n", errout.str());
check_preprocess_suppress(
"void foo() {\n"
" switch (a) {\n"
" int x;\n"
" case 1:\n"
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void selfAssignment()