Fix #11785 Syntax error: typedef not first keyword in statement (#5178)

This commit is contained in:
chrchr-github 2023-06-21 18:26:28 +02:00 committed by GitHub
parent b26bfc9b4f
commit 9a95d4fe67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -8246,7 +8246,8 @@ void Tokenizer::findGarbageCode() const
prev = prev->previous();
if (Token::Match(prev, "%op%|%num%|%str%|%char%")) {
if (!Token::simpleMatch(tok->tokAt(-2), "operator \"\" if") &&
!Token::simpleMatch(tok->tokAt(-2), "extern \"C\""))
!Token::simpleMatch(tok->tokAt(-2), "extern \"C\"") &&
!Token::simpleMatch(prev, "> typedef"))
syntaxError(tok, prev == tok->previous() ? (prev->str() + " " + tok->str()) : (prev->str() + " .. " + tok->str()));
}
}

View File

@ -6918,6 +6918,9 @@ private:
ASSERT_NO_THROW(tokenizeAndStringify("template <class T> constexpr int n = 1;\n"
"template <class T> T a[n<T>];\n"));
ASSERT_EQUALS("std :: vector < int > x ;", // #11785
tokenizeAndStringify("std::vector<int> typedef v; v x;\n"));
// op op
ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { dostuff (x==>y); }"), InternalError, "syntax error: == >");