diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d13e9034b..fd9fab835 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9052,9 +9052,14 @@ void Tokenizer::findGarbageCode() const "typedef", "while"}; for (const Token *tok = tokens(); tok; tok = tok->next()) { - if (Token::Match(tok, "%name% %name%") && nonConsecutiveKeywords.count(tok->str()) == 1 && nonConsecutiveKeywords.count(tok->next()->str()) == 1) + if (!tok->isName() || nonConsecutiveKeywords.count(tok->str()) == 0) + continue; + if (Token::Match(tok, "%name% %name%") && nonConsecutiveKeywords.count(tok->next()->str()) == 1) syntaxError(tok); - if (Token::Match(tok, "%op% %name%") && nonConsecutiveKeywords.count(tok->next()->str()) == 1) + const Token *prev = tok; + while (prev && prev->isName()) + prev = prev->previous(); + if (Token::Match(prev, "%op%|%num%|%str%|%char%")) syntaxError(tok); } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 0b624f948..4c2526ade 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -1658,6 +1658,7 @@ private: ASSERT_THROW(checkCode("void f(){x='0'++'0'(return)[];}"), InternalError); // #9063 ASSERT_THROW(checkCode("void f() { x= 'x' > typedef name5 | ( , ;){ } (); }"), InternalError); // #9067 ASSERT_THROW(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }"), InternalError); // #9068 + ASSERT_THROW(checkCode("void f() { x= y{ } name5 y[ ] + y ^ name5 ^ name5 for ( ( y y y && y y y && name5 ++ int )); }"), InternalError); // #9069 } void enumTrailingComma() {