Syntax error: if (retval==)

This commit is contained in:
Daniel Marjamäki 2019-11-23 18:50:31 +01:00
parent fb1d60bfb1
commit ebd32cfd73
2 changed files with 8 additions and 0 deletions

View File

@ -9419,6 +9419,12 @@ void Tokenizer::findGarbageCode() const
if (match1 && match2)
syntaxError(tok);
}
if (Token::Match(tok, "%comp%|+|-|/|% )|]|}")) {
if (isC())
syntaxError(tok, tok->str() + tok->next()->str());
if (tok->str() != ">" && !Token::simpleMatch(tok->previous(), "operator"))
syntaxError(tok, tok->str() + " " + tok->next()->str());
}
if (Token::Match(tok, "( %any% )") && tok->next()->isKeyword() && !Token::simpleMatch(tok->next(), "void"))
syntaxError(tok);
if (Token::Match(tok, "%num%|%bool%|%char%|%str% %num%|%bool%|%char%|%str%") && !Token::Match(tok, "%str% %str%"))

View File

@ -7905,6 +7905,8 @@ private:
ASSERT_THROW(tokenizeAndStringify("void foo() { for_chain( if (!done) done = 1); }"), InternalError);
ASSERT_THROW(tokenizeAndStringify("void foo() { for_chain( a, b, if (!done) done = 1); }"), InternalError);
ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { if (retval==){} }"), InternalError, "syntax error: == )");
// after (expr)
ASSERT_NO_THROW(tokenizeAndStringify("void f() { switch (a) int b; }"));