Skip to content

Commit 9a95d4f

Browse files
Fix #11785 Syntax error: typedef not first keyword in statement (#5178)
1 parent b26bfc9 commit 9a95d4f

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8246,7 +8246,8 @@ void Tokenizer::findGarbageCode() const
82468246
prev = prev->previous();
82478247
if (Token::Match(prev, "%op%|%num%|%str%|%char%")) {
82488248
if (!Token::simpleMatch(tok->tokAt(-2), "operator \"\" if") &&
8249-
!Token::simpleMatch(tok->tokAt(-2), "extern \"C\""))
8249+
!Token::simpleMatch(tok->tokAt(-2), "extern \"C\"") &&
8250+
!Token::simpleMatch(prev, "> typedef"))
82508251
syntaxError(tok, prev == tok->previous() ? (prev->str() + " " + tok->str()) : (prev->str() + " .. " + tok->str()));
82518252
}
82528253
}

test/testtokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6918,6 +6918,9 @@ class TestTokenizer : public TestFixture {
69186918
ASSERT_NO_THROW(tokenizeAndStringify("template <class T> constexpr int n = 1;\n"
69196919
"template <class T> T a[n<T>];\n"));
69206920

6921+
ASSERT_EQUALS("std :: vector < int > x ;", // #11785
6922+
tokenizeAndStringify("std::vector<int> typedef v; v x;\n"));
6923+
69216924

69226925
// op op
69236926
ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { dostuff (x==>y); }"), InternalError, "syntax error: == >");

0 commit comments

Comments
 (0)