diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d5a02c03c..0d11f48a0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8508,6 +8508,12 @@ void Tokenizer::findGarbageCode() const unknownMacroError(tok->linkAt(1)->previous()); } + // Assign/increment/decrement literal + for (const Token *tok = tokens(); tok; tok = tok->next()) { + if (Token::Match(tok,"%num%|%str%|%char% %assign%|++|--")) + syntaxError(tok); + } + for (const Token *tok = tokens(); tok; tok = tok->next()) { if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... } if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|(|)|,")) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index ae2f2743d..4ba896d05 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -1654,6 +1654,7 @@ private: void syntaxErrorFuzzerCliType1() { ASSERT_THROW(checkCode("void f(){x=0,return return''[]()}"), InternalError); + ASSERT_THROW(checkCode("void f(){x='0'++'0'(return)[];}"), InternalError); // #9063 } void enumTrailingComma() {