Fixed #8873 (Add syntaxError when there is no RHS for +-)

This commit is contained in:
Daniel Marjamäki 2018-12-01 17:29:41 +01:00
parent ffef44af4c
commit 96929c53c0
2 changed files with 9 additions and 1 deletions

View File

@ -8533,6 +8533,8 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::Match(tok, "%cop%|= ]") && !(isCPP() && Token::Match(tok->previous(), "[|, &|= ]")))
syntaxError(tok);
if (Token::Match(tok, "[+-] [;,)]}]"))
syntaxError(tok);
}
// ternary operator without :

View File

@ -231,6 +231,7 @@ private:
TEST_CASE(garbageCode198); // #8383
TEST_CASE(garbageCode199); // #8752
TEST_CASE(garbageCode200); // #8757
TEST_CASE(garbageCode201); // #8873
TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1
@ -1426,7 +1427,7 @@ private:
}
void garbageCode181() {
checkCode("int test() { int +; }");
ASSERT_THROW(checkCode("int test() { int +; }"), InternalError);
}
// #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }"
@ -1551,6 +1552,11 @@ private:
ASSERT_THROW(checkCode("(){e break,{(case)!{e:[]}}}"), InternalError);
}
// #8873
void garbageCode201() {
ASSERT_THROW(checkCode("void f() { std::string s=\"abc\"; return s + }"), InternalError);
}
void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858