Fixed #9445 (Syntax error on typeof word in C)

This commit is contained in:
Daniel Marjamäki 2020-09-08 17:12:54 +02:00
parent 6e4085f3d8
commit e802d85315
2 changed files with 6 additions and 1 deletions

View File

@ -9656,7 +9656,9 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::simpleMatch(tok, ",") &&
!Token::Match(tok->tokAt(-2), "[ = , &|%name%")) {
if (Token::Match(tok->previous(), "(|[|{|<|%assign%|%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|::|sizeof|throw|decltype|typeof"))
if (Token::Match(tok->previous(), "(|[|{|<|%assign%|%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|::|sizeof"))
syntaxError(tok);
if (isCPP() && Token::Match(tok->previous(), "throw|decltype|typeof"))
syntaxError(tok);
if (Token::Match(tok->next(), ")|]|>|%assign%|%or%|%oror%|==|!=|/|>=|<=|&&"))
syntaxError(tok);

View File

@ -8175,6 +8175,9 @@ private:
ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { assert(a==()); }"), InternalError, "syntax error: ==()");
ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { assert(a+()); }"), InternalError, "syntax error: +()");
// #9445 - typeof is not a keyword in C
ASSERT_NO_THROW(tokenizeAndStringify("void foo() { char *typeof, *value; }", false, false, Settings::Native, "test.c"));
}