Fixed #8184 (Syntax error: case outside switch)

This commit is contained in:
Daniel Marjamäki 2017-09-15 22:37:31 +02:00
parent 4bd251a6d9
commit 2e6d78bd08
2 changed files with 16 additions and 0 deletions

View File

@ -8207,6 +8207,16 @@ const Token * Tokenizer::findGarbageCode() const
}
}
// case keyword must be inside switch
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "switch (") && Token::simpleMatch(tok->linkAt(1), ") {"))
tok = tok->linkAt(1)->linkAt(1);
else if (tok->str() == "(")
tok = tok->link();
else if (tok->str() == "case")
return tok;
}
for (const Token *tok = tokens(); tok ; tok = tok->next()) {
if (!Token::simpleMatch(tok, "for (")) // find for loops
continue;

View File

@ -224,6 +224,7 @@ private:
TEST_CASE(templateSimplifierCrashes);
TEST_CASE(syntaxErrorFirstToken); // Make sure syntax errors are detected and reported
TEST_CASE(syntaxErrorLastToken); // Make sure syntax errors are detected and reported
TEST_CASE(syntaxErrorCase);
TEST_CASE(enumTrailingComma);
}
@ -1482,6 +1483,11 @@ private:
// ASSERT_THROW( , InternalError)
}
void syntaxErrorCase() {
// case must be inside switch block
ASSERT_THROW(checkCode("void f() { switch (a) {}; case 1: }"), InternalError);
}
void enumTrailingComma() {
ASSERT_THROW(checkCode("enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ;"), InternalError); // #8079
}