Fix #8758 (add syntax error for invalid code) (#2466)

This commit is contained in:
Rikard Falkeborn 2020-01-01 15:46:09 +01:00 committed by amai2012
parent f23d880a7e
commit 7514544d94
2 changed files with 6 additions and 1 deletions

View File

@ -9439,7 +9439,7 @@ void Tokenizer::findGarbageCode() const
if (match1 && match2)
syntaxError(tok);
}
if (Token::Match(tok, "%comp%|+|-|/|% )|]|}")) {
if (Token::Match(tok, "%or%|%oror%|~|^|!|%comp%|+|-|/|% )|]|}")) {
if (isC())
syntaxError(tok, tok->str() + tok->next()->str());
if (tok->str() != ">" && !Token::simpleMatch(tok->previous(), "operator"))

View File

@ -244,6 +244,7 @@ private:
TEST_CASE(garbageCode210); // #8762
TEST_CASE(garbageCode211); // #8764
TEST_CASE(garbageCode212); // #8765
TEST_CASE(garbageCode213); // #8758
TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1
@ -1661,6 +1662,10 @@ private:
ASSERT_THROW(checkCode("{(){}[]typedef r n00e0[](((n00e0 0((;()))))){(0 typedef n00e0 bre00 n00e0())}[]();typedef n n00e0()[],(bre00)}"), InternalError);
}
void garbageCode213() { // #8758
ASSERT_THROW(checkCode("{\"\"[(1||)];}"), InternalError);
}
void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858